Skip to content

Pillar access during state.highstate seems to be unavailable when setting saltenv arg #20506

Closed

Description

@arnisoph
# salt-call --versions
           Salt: 2014.7.0-1596-g5586c20
         Python: 2.7.3 (default, Mar 13 2014, 11:03:55)
         Jinja2: 2.6
       M2Crypto: 0.21.1
 msgpack-python: 0.1.10
   msgpack-pure: Not Installed
       pycrypto: 2.6
        libnacl: Not Installed
         PyYAML: 3.10
          ioflo: Not Installed
          PyZMQ: 13.1.0
           RAET: Not Installed
            ZMQ: 3.2.3
           Mako: Not Installed

Git (based on 2014.7 branch): https://github.com/bechtoldt/salt/tree/2014.7-arbe

# cat /etc/salt/minion
master: 127.0.0.1
log_level: debug
# cat /etc/salt/master
file_roots:
  prod:
    - /srv/salt/prod/
pillar_roots:
  base:
    - /srv/pillar
pillar_opts: False
# cat /srv/salt/prod/top.sls
prod:
  '*':
    - test_state
# cat /srv/salt/prod/test_state.sls
test:
  file:
    - managed
    - name: /var/tmp/test_file
    - contents: |
        {{ salt['pillar.items']() }}
# cat /srv/pillar/top.sls
base:
  '*':
    - test
# cat /srv/pillar/test.sls
foo: bar
# tree /srv/
/srv/
├── pillar
│   ├── test.sls
│   └── top.sls
└── salt
    └── prod
        ├── test_state.sls
        └── top.sls

3 directories, 4 files
# rm -f /var/tmp/test_file
# salt '*' state.sls test_state saltenv=prod
ipm1039:
----------
          ID: test
    Function: file.managed
        Name: /var/tmp/test_file
      Result: True
     Comment: File /var/tmp/test_file updated
     Started: 19:54:37.940317
    Duration: 2.514 ms
     Changes:
              ----------
              diff:
                  New file

Summary
------------
Succeeded: 1 (changed=1)
Failed:    0
------------
Total states run:     1
# cat /var/tmp/test_file
{'foo': 'bar'}
# salt '*' state.highstate saltenv=prod
ipm1039:
----------
          ID: test
    Function: file.managed
        Name: /var/tmp/test_file
      Result: True
     Comment: File /var/tmp/test_file updated
     Started: 19:54:53.186957
    Duration: 2.467 ms
     Changes:
              ----------
              diff:
                  ---
                  +++
                  @@ -1 +1 @@
                  -{'foo': 'bar'}
                  +{}


Summary
------------
Succeeded: 1 (changed=1)
Failed:    0
------------
Total states run:     1
# cat /var/tmp/test_file
{}

Activity

  1. steverweber commented on Feb 8, 2015

    @steverweber
    Contributor

    try - contents: {{ pillar|json }}

  2. steverweber commented on Feb 8, 2015

    @steverweber
    Contributor

    fyi i think pillar_opts: False is the default now

  3. steverweber commented on Feb 8, 2015

    @steverweber
    Contributor

    one other thing... give it a
    salt minion saltutils.refresh_pillar
    salt minion pillar.raw

  4. arnisoph commented on Feb 8, 2015

    @arnisoph
    ContributorAuthor
    # salt -C '*1039*' pillar.items
    ipm1039:
        ----------
        foo:
            bar
    
    # salt -C '*1039*' pillar.raw
    ipm1039:
        ----------
        foo:
            bar
    
    # salt -C '*1039*' saltutil.refresh_pillar
    ipm1039:
        True
    
    # salt '*' state.highstate saltenv=prod
    ipm1039:
    ----------
              ID: test
        Function: file.managed
            Name: /var/tmp/test_file
          Result: True
         Comment: File /var/tmp/test_file is in the correct state
         Started: 20:14:49.050043
        Duration: 274.013 ms
         Changes:
    
    Summary
    ------------
    Succeeded: 1
    Failed:    0
    ------------
    Total states run:     1
    
    # salt '*' state.sls test_state saltenv=prod
    ipm1039:
    ----------
              ID: test
        Function: file.managed
            Name: /var/tmp/test_file
          Result: True
         Comment: File /var/tmp/test_file updated
         Started: 20:15:03.070849
        Duration: 466.677 ms
         Changes:
                  ----------
                  diff:
                      ---
                      +++
                      @@ -1 +1 @@
                      -{}
                      +{'foo': 'bar'}
    
    
    Summary
    ------------
    Succeeded: 1 (changed=1)
    Failed:    0
    ------------
    Total states run:     1
    
    # salt '*' state.highstate saltenv=prod
    ipm1039:
    ----------
              ID: test
        Function: file.managed
            Name: /var/tmp/test_file
          Result: True
         Comment: File /var/tmp/test_file updated
         Started: 20:15:08.350499
        Duration: 253.584 ms
         Changes:
                  ----------
                  diff:
                      ---
                      +++
                      @@ -1 +1 @@
                      -{'foo': 'bar'}
                      +{}
    
    
    Summary
    ------------
    Succeeded: 1 (changed=1)
    Failed:    0
    ------------
    Total states run:     1
    
  5. steverweber commented on Feb 8, 2015

    @steverweber
    Contributor

    Yap something is wrong here!

  6. steverweber commented on Feb 8, 2015

    @steverweber
    Contributor
    pillar_roots:
      base:
        - /srv/pillar
    

    where is the pillar for prod?

  7. arnisoph commented on Feb 8, 2015

    @arnisoph
    ContributorAuthor

    @steverweber no worries, now I'm sure I'm not crazy (yet)

  8. steverweber commented on Feb 8, 2015

    @steverweber
    Contributor

    if i were you i would start with everything in base.
    also perhaps try the latest release of salt to see if this issue was solved.

  9. changed the title [-]Pillar access in state.sls and state.highstate differs[/-] [+]Pillar access in state.highstate seems to be unavailable[/+] on Feb 8, 2015
  10. changed the title [-]Pillar access in state.highstate seems to be unavailable[/-] [+]Pillar access during state.highstate seems to be unavailable[/+] on Feb 8, 2015
  11. arnisoph commented on Feb 8, 2015

    @arnisoph
    ContributorAuthor

    FACEPALM

    # salt '*' state.highstate test=False
    ipm1039:
    ----------
              ID: test
        Function: file.managed
            Name: /var/tmp/test_file
          Result: True
         Comment: File /var/tmp/test_file updated
         Started: 22:44:46.260340
        Duration: 261.941 ms
         Changes:
                  ----------
                  diff:
                      ---
                      +++
                      @@ -1 +1 @@
                      -{}
                      +{'foo': 'bar'}
    
    
    Summary
    ------------
    Succeeded: 1 (changed=1)
    Failed:    0
    ------------
    Total states run:     1
    
    # echo > /var/tmp/test_file
    # salt '*' state.highstate test=False saltenv=base
    ipm1039:
    ----------
              ID: states
        Function: no.None
          Result: False
         Comment: No Top file or external nodes data matches found
         Started:
        Duration:
         Changes:
    
    Summary
    ------------
    Succeeded: 0
    Failed:    1
    ------------
    Total states run:     1
    

    So what the heck is state.highstate() doing with saltenv?

  12. changed the title [-]Pillar access during state.highstate seems to be unavailable[/-] [+]Pillar access during state.highstate seems to be unavailable when setting saltenv arg[/+] on Feb 8, 2015
  13. rallytime commented on Feb 9, 2015

    @rallytime
    Contributor

    Thanks for the report @bechtoldt, and for the responses @steverweber.

    I am not entirely sure if state.highstate was designed to do anything with saltenv since by definition highstate is cross-environment.

  14. added
    pending-discussion
    on Feb 9, 2015
  15. added this to the Blocked milestone on Feb 9, 2015
  16. arnisoph commented on Feb 10, 2015

    @arnisoph
    ContributorAuthor

    @rallytime I agree, setting the saltenv arg does not make sense when using state.highstate.

    But the interesting part starts in the code: https://github.com/saltstack/salt/blob/develop/salt/modules/state.py#L461

  17. basepi commented on Feb 10, 2015

    @basepi
    Contributor

    Interesting, we'll have to investigate if the saltenv is actually doing anything inside of the HighState class.

  18. added
    bug
    severity-medium
    and removed
    pending-discussion
    on Feb 10, 2015
  19. modified the milestones: Approved, Blocked on Feb 10, 2015
  20. basepi commented on Feb 10, 2015

    @basepi
    Contributor

    Wait, so I'm confused about this issue. Is this issue about state.highstate or state.sls with saltenv? Your original example makes me think state.sls, but the title and last few comments say otherwise.

  21. arnisoph commented on Feb 19, 2015

    @arnisoph
    ContributorAuthor

    @basepi as @rallytime already stated state.highstate was meant.

    state.highstate uses saltenv for a purpose I don't understand:

    elif 'saltenv' in kwargs:

  22. pruiz commented on Feb 24, 2015

    @pruiz
    Contributor

    Well, I for example tend to use "state.highstate test=true saltenv=GIT_BRANCH_XYZ" as a way to test application of states from a git branch on our salt states repository.

    This is a really useful pattern, but not having access to pillars, kills it.. :(

  23. pruiz commented on Feb 24, 2015

    @pruiz
    Contributor

    Even this 'hackish' way does not work either:

    salt-call -l debug state.highstate test=True saltenv=some/branch "pillar=$(echo $(salt-call --out=json pillar.items) )"
    
  24. pruiz commented on Feb 24, 2015

    @pruiz
    Contributor

    Turns out pillar.items/pillar.raw returns a dict with a single key (local) even when outputing as json, so I had to relay on an even more 'hackish way' to get it to work:

    salt-call -l debug state.highstate test=True saltenv=some/branch "pillar=$(echo $(salt-call --out=json pillar.raw) |sed -e 's,^{ "local": ,,' -e 's, }$,,' )"
    

    But at least, it works.. ;)

  25. added
    Core
    on Apr 8, 2015
  26. arnisoph commented on Jul 11, 2015

    @arnisoph
    ContributorAuthor

    I'm closing this since saltenv isn't a supported argument.

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

    Corebugseverity-medium

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions