Skip to content

feature request: target by state ID #11868

Closed

Description

@Mrten

I'd like to target highstate runs by state. This way I could, say, restart all apaches at the same time and be sure that I haven't missed any.

Like this:

salt -S apache state.highstate

Explanation: I write my states for, say, apache, with one basic state that sets everything that I want the same for all apaches (like the LogFormat, the mimesettings, etc) and include: that basic state from every other apache that gets deployed, however different its usecase may be.

When one is then confronted with something like the Heartbleed OpenSSL bug one would like to upgrade/restart all those apaches in one go.

I could work around this with pillar values but that feels like a kludge to me.

Activity

  1. basepi commented on Apr 14, 2014

    @basepi
    Contributor

    So what part of the state are you targeting with "apache"? The state ID? Is it supposed to include globbing? If you could clarify exactly what you want your example above to target, that would be really helpful.

  2. added this to the milestone on Apr 14, 2014
  3. Mrten commented on Apr 15, 2014

    @Mrten
    ContributorAuthor

    OK, so here's an example from my config tree that I've edited slightly for brevity so please don't expect all names to line up:

    top.sls:

    ...
     'osm-1':
        - machine.osm.apache
        - ...
    

    machine/osm/apache/init.sls:

    include:
      - apache
    
    extend:
      /etc/apache2/sites:
        file.recurse:
          - source: salt://machine/osm/apache/sites
      /etc/apache2/conf/listen.conf:
        file.managed:
          - source: salt://machine/osm/apache/listen.conf
    ...
    

    apache/init.sls:

    apache-pkgs:
      pkg.installed:
        - pkgs:
          - apache2
    
    apache2:
      service.running:
        - watch:
          - file: /etc/apache2/apache2.conf
          - cmd: apache-configtest
    
    /etc/apache2/apache2.conf:
      file.managed:
        - source: salt://apache/apache2.conf
        - require:
          - pkg: apache-pkgs
    
    /etc/apache2/sites:
      file.recurse:
        - source: salt://apache/sites
        - template: jinja
        - file_mode: 444
    
    /etc/apache2/conf/listen.conf:
      file.managed:
        - source: salt://apache/listen.conf
        - template: jinja
        - mode: 444
    
    delete-apache-files:
      file.absent:
        - names:
          - /etc/apache2/httpd.conf
          - /etc/apache2/ports.conf
          - /etc/apache2/sites-enabled
    
    enable-apache-ssl.conf:
      file.symlink:
        - name: /etc/apache2/mods-enabled/ssl.conf
        - target: /etc/apache2/mods-available/ssl.conf
    ...
    [more stuff related to SSL, iterates over pillar dict]
    

    etc, etc. You can see that I 'override', for example, /etc/apache2/sites in the machine-specific conf but leave lots of other states unaffected, so this way of writing configs is very useful to provide a default config that needs only small tweaks to be useful on different machines.

    I'm not up to speed with the salt terminology, my use of 'apache' is referring to a filename, or rather a directory (apache/init.sls), but I guess a state ID (apache-pkgs, apache2, delete-apache-files) would work too.

    I don't know how useful globbing would be, you'd need to be very careful with state naming.

  4. changed the title [-]target b [/-] [+]target by state ID[/+] on Apr 15, 2014
  5. changed the title [-]target by state ID[/-] [+]feature request: target by state ID[/+] on Apr 15, 2014
  6. basepi commented on Apr 17, 2014

    @basepi
    Contributor

    So the targeting system is used for minion targeting, not for state targeting. In your example above, how would the master know which minions to target with the command?

    Also, I may be missing something, but doesn't salt '*' state.sls apache fit your use case?

  7. Mrten commented on Apr 17, 2014

    @Mrten
    ContributorAuthor

    I'm asking for a command-line option. Parallel to salt -N [group] state.highstate, salt -L '[list-of-minions]' state.highstate, salt -G [grain] state.highstate, salt -I [pillar] state.highstate, etc.

  8. Mrten commented on Apr 18, 2014

    @Mrten
    ContributorAuthor

    And it's not that I want to run a specific state (your second question), I want to be unlimited ([insert evil laugh here]). To be specific further, no, it does not fit my use case, because the command you suggest would run the apache state on all minions, installing apache on all minions. I'd like it the other way around; to run a command on all minions that already have apache (or nginx or hiawatha or gcc or tomcat or whatever) installed (via a salt state of course).

    To answer your first question: I thought that all commands were always sent to all minions and that the minion decides whether the command is meant for it or not. So it would not be the master that decides, it would be the minion that checks its list of states, sees whether it has the state in that list, and decides based on that whether it needs to run the command or not.

    I hope I'm making more sense now...

  9. basepi commented on Apr 18, 2014

    @basepi
    Contributor

    I think I'm following better, though I'm not sure if this is a feature that's reasonable given the way the state system is currently setup. I'll have to ping @thatch45 on it, see what he thinks.

  10. jeff-minard-ck commented on Nov 25, 2014

    @jeff-minard-ck

    I'm also looking for the same thing. We will often edit one or two states and want to get those changes deployed out -- in a large deployment it can be difficult to determine which machines will get a specific state (includes obscure this quite a bit). Doing a massive bulk salt '*' state.highstate isn't reasonable (because that can be a bit scary and, more practically, would take an absurd amount of time).

    To clarify this requests we'd like to be able to do a "reverse lookup" of sorts where we can target by saying "find every machine that this state would apply to during a high state" and use those machines as the target.

  11. 17 remaining items

  12. stale commented on Jan 8, 2020

    @stale

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

  13. added
    ZD
    on Oct 7, 2020
  14. oeuftete commented on Oct 7, 2020

    @oeuftete
    Contributor

    ZD-5829.

  15. wwalker commented on Oct 7, 2020

    @wwalker

    Please add this.

    The use case is very common (as said by jeff-minard-ck) #11868 (comment)

    I currently do this in a script. roughly:

    mkdir -p ~/.show_tops
    for i in $(salt-run manage.up | sed -e 's/- //')
    do
      # shellcheck disable=SC2094
      (salt "$i" state.show_top | tail -n +4 | head -n -10 > "$i")
    done
    
    wait
    egrep -wl " - $1\$" ~/.show_tops/*
    

    It is very handy, but also HEAVY.

  16. Mrten commented on Oct 7, 2020

    @Mrten
    ContributorAuthor

    Please add this.

    Thanks for the idea! show_top doesn't give me what I want, but state.show_lowstate would, given some judicious grepping. (The bugreport above came from some experimenting :)

    root@machine:~# salt web-1 state.show_lowstate --out json | fgrep __sls__ | tr -d \, | sort | uniq | fgrep apache
                "__sls__": "apache"
                "__sls__": "machine.web.apache"
                "__sls__": "php-apache"
    

    Some tweaking needed, but at least its going somewhere.

  17. dmurphy18 commented on Sep 25, 2023

    @dmurphy18
    Contributor

    @Mrten Closing this due to age, the old version of Salt and Python 2.
    Can you retest this with the latest release of Salt (currently 3006.3) and if still an issue, please open a new issue, which will have metrics in tracking issues.

    This looks more like a feature request, if still interested, can you open a feature request using the new template, this allows for matrices from the template to track issues and allows for more information as to what problems are encountered or requested.

  18. Mrten commented on Sep 26, 2023

    @Mrten
    ContributorAuthor

    oh, blah. see issue 65292

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureZD

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions