salt icon indicating copy to clipboard operation
salt copied to clipboard

Allow "multiple state declarations of the same type" when function is different

Open srkunze opened this issue 10 years ago • 34 comments

It would be great if one could do the following:

apache_sites:
  apache_site.enabled:
    - names:
      - my-server
      - your-server
  apache_site.disabled:
    - names:
      - 000-default

Right now, we circumvent the error by introducting another state such as:

apache_sites_enabled:
  apache_site.enabled:
    - names:
      - my-server
      - your-server

apache_sites_disabled:
  apache_site.disabled:
    - names:
      - 000-default

srkunze avatar Aug 19 '16 09:08 srkunze

@srkunze I believe this is a duplicate of #29142 . If you agree please feel free to close this issue and comment on #29142 and we will track this feature request there. Thanks

Ch3LL avatar Aug 19 '16 20:08 Ch3LL

@Ch3LL I looked that issue up already but it's not 100% the same I think.

They need 2x "apache_site.enabled". I need "apache_site.enabled" + "apache_site.disabled" which is different.

So, I let you the choice to close the issue if you think the internal implementation would be the same. :)

srkunze avatar Aug 19 '16 21:08 srkunze

Thanks for clarifying . Will add this as a feature request instead of treating as a duplciate thanks.

Ch3LL avatar Sep 21 '16 21:09 Ch3LL

Glad to see that this is already in the queue. Just wanted to add another (probably more common) example ... file.managed and file.symlink

wayne-weibel avatar Dec 28 '16 14:12 wayne-weibel

I ran into this exact issue today, with the following use case: locale.present and locale.system

jktr avatar Jul 02 '17 00:07 jktr

same here trying to do:

diamond:
   file.directory: 
    .....
   file.managed:
   ....

btorch avatar Jul 26 '17 14:07 btorch

kafka-config-dir:
  file.absent:
    - name: /not/useful/dir
  file.directory:
    - name: /some/useful/dir

houming818 avatar Oct 03 '17 07:10 houming818

Ran into this as well using:

lvm.pv_present:
  - name: /dev/xvdd
lvm.vg_present:
  - name: vol_grp1
lvm.lv_present:
  - name: logical_vol1

ghost avatar Nov 09 '17 17:11 ghost

I'd like this feature as well

/etc/ssh/sshd_config:
  file.uncomment:
    - regex: '.*AuthorizedKeysFile.*'

  file.replace:
    - pattern: '(.*LoginGraceTime.*)'
    - repl: 'LoginGraceTime 120'
    - show_changes: true 

tbennett6421 avatar Nov 15 '17 23:11 tbennett6421

Another use case:

Configure network time service:
  pkg.purged:
    - pkgs:
      - ntp
      - ntp-doc
      - ntpdate

  pkg.installed:
    - name: chrony

madfordmac avatar Sep 06 '18 08:09 madfordmac

One of the most 'in your face' features that should be added...but I'm guessing backwards compatibility limits this.

naveen-rasiah avatar Jan 17 '19 01:01 naveen-rasiah

And another, possibly quite common use case!

edit some file two ways when needed:
  file.replace:
    - name: '/some/file/path'
    - pattern: 'replace_me'
    - repl: 'better_string'
  file.line:
    - name: '/same/file/path'
    - match: 'delete_this_string'
    - mode: delete

faelin avatar Apr 18 '19 17:04 faelin

I would have liked to setup passwordless ssh keys to a repo host (without using 'id-rsa' for the keyfile) in one state

ssh_repo_passwordless:
  file.copy:
    - name: /root/.ssh/your_repo_rsa_priv
    - source: salt://sshkeys/your_repo_rsa_priv
    - user: root
    - group: root
    - mode: 0600
  file.append:
    - name: /root/.ssh/config
    - text: |
         Host your_repo your_repoIP
           HostName your_repoIP
           User repo_user
           IdentityFile /root/.ssh/your_repo_rsa_priv

benfiedler avatar Jun 19 '19 16:06 benfiedler

additional case:

the alternatives system: https://docs.saltstack.com/en/latest/ref/states/all/salt.states.alternatives.html

openjdk.set.java:
  alternatives.install:
    - name: java
    - link: /usr/bin/java
    - path: /usr/lib/jvm/java-1.7.0-openjdk.x86_64/bin/java
    - priority: 5
    - require:
      - pkg: openjdk.install
  alternatives.set:
    - name: java
    - path: /usr/lib/jvm/java-1.7.0-openjdk.x86_64/bin/java

ssoto2 avatar Jun 20 '19 15:06 ssoto2

👍

dsaard avatar Oct 18 '19 07:10 dsaard

Another use case:

/home/{{ user }}/.ssh/config:
  file.managed:
    - user: {{ user }}
    - mode: '0644'
    - makedirs: True
    - dir_mode: '0766'
    - source:

  file.append:
   - name: /home/{{ user }}/.ssh/config
   - text:
     - "Host: git.example.org"
     - "  IdentityFile /etc/salt/rsa.id"

file.append would create file with the wrong permission (aka root) if the files doesn't exist and you can't define that info. So you must run an empty manage that will create an empty file if absent with the proper permissions, then append logically follow.

pbusquemdf avatar Oct 21 '19 22:10 pbusquemdf

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

stale[bot] avatar Jan 07 '20 18:01 stale[bot]

not stale

dsaard avatar Jan 09 '20 07:01 dsaard

Thank you for updating this issue. It is no longer marked as stale.

stale[bot] avatar Jan 09 '20 07:01 stale[bot]

👍

cdalvaro avatar Mar 20 '20 09:03 cdalvaro