Skip to content

yamlex !reset doesn't work when combining pillars across environments #18665

Closed

Description

@wickedbill

I've come across a strange bug - or something I'm doing wrong that I can't pinpoint. I'm using the yamlex renderer and !reset, however reset is not honored when run through salt.

If I run the same yaml through the yamlex deserializer on the command line it works as expected. I'm running 2014.7.0.

Here's an example of the issue I've found:

[root@salt-master pillar]# cat base/ssh.sls
#!yamlex
ssh: !aggregate
  keys: !aggregate
    - one: b
      two: a

[root@salt-master pillar]# cat group/ssh.sls
#!yamlex
!reset ssh: !aggregate
  !reset keys: !aggregate
    - three: a
      four: b

[root@salt-master pillar]# cat base/top.sls
base:
  '*':
    - ssh
group:
  '*':
    - ssh

[root@salt-master pillar]# salt 'qa-server*' pillar.items
qa-server:
    ----------
    ssh:
        ----------
        keys:
            |_
              ----------
              four:
                  b
              three:
                  a
            |_
              ----------
              one:
                  b
              two:
                  a

The above should have reset the 'keys' array and contained only the single array with 'four' and 'three' keys. The below test is how I expected this to act, and it appears to work correctly if run on the command line with the same yaml.

[root@salt-master pillar]# cat test.py
#!/usr/bin/python

from salt.utils.serializers.yamlex import serialize, deserialize

parseme = '''
ssh: !aggregate
  keys: !aggregate
    - one: b
      two: a

!reset ssh: !aggregate
  !reset keys: !aggregate
    - three: a
      four: b
'''

print deserialize(parseme)
[root@salt-master pillar]# python test.py
{ssh: {keys: [{three: a, four: b}]}}

Activity

  1. jfindlay commented on Dec 4, 2014

    @jfindlay
    Contributor

    @wickedbill, I am unable to reproduce this bug. I'm not sure how yamlex is
    being disabled on your system. This is what I did, please comment if I have
    done something wrong.

    setup

    jmoney-main ~ master # lsb_release -a
    No LSB modules are available.
    Distributor ID: Debian
    Description:    Debian GNU/Linux testing (jessie)
    Release:        testing
    Codename:       jessie
    
    jmoney-main ~ master # salt --versions
               Salt: 2014.7.0
             Python: 2.7.8 (default, Oct 18 2014, 12:50:18)
             Jinja2: 2.7.3
           M2Crypto: 0.21.1
     msgpack-python: 0.4.2
       msgpack-pure: Not Installed
           pycrypto: 2.6.1
            libnacl: Not Installed
             PyYAML: 3.11
              ioflo: Not Installed
              PyZMQ: 14.4.0
               RAET: Not Installed
                ZMQ: 4.0.5
               Mako: 1.0.0
    
    jmoney-main ~ master # cat /etc/salt/master
    pillar_roots:
      base:
        - /srv/pillar/base
      group:
        - /srv/pillar/group
    
    jmoney-main ~ master # cat /srv/pillar/base/top.sls
    base:
      '*':
        - ssh
    group:
      '*':
        - ssh
    
    jmoney-main ~ master # cat /srv/pillar/base/ssh.sls
    #!yamlex
    ssh: !aggregate
      keys: !aggregate
        - one: b
          two: a
    
    jmoney-main ~ master # cat /srv/pillar/group/ssh.sls
    #!yamlex
    !reset ssh: !aggregate
      !reset keys: !aggregate
        - three: a
          four: b
    

    execution

    jmoney-main ~ master # salt jmoney-main pillar.items ssh
    jmoney-main:
        ----------
        ssh:
            ----------
            keys:
                |_
                  ----------
                  four:
                      b
                  three:
                      a
    
  2. added
    bug
    severity-low
    on Dec 4, 2014
  3. added this to the Blocked milestone on Dec 4, 2014
  4. inthecloud247 commented on Dec 23, 2014

    @inthecloud247
    Contributor

    I'm experiencing the same issue. Works in my python test script, but not when using pillar.items across different environments. It does work for me if I move everything into the same pillar sls file though...

    root@vagrant-ubuntu-trusty-64:~# lsb_release -a
    No LSB modules are available.
    Distributor ID: Ubuntu
    Description:    Ubuntu 14.04.1 LTS
    Release:    14.04
    Codename:   trusty
    root@vagrant-ubuntu-trusty-64:~# 
    root@vagrant-ubuntu-trusty-64:~# salt-call --versions
               Salt: 2014.7.0
             Python: 2.7.6 (default, Mar 22 2014, 22:59:56)
             Jinja2: 2.7.2
           M2Crypto: 0.21.1
     msgpack-python: 0.3.0
       msgpack-pure: Not Installed
           pycrypto: 2.6.1
            libnacl: Not Installed
             PyYAML: 3.10
              ioflo: Not Installed
              PyZMQ: 14.0.1
               RAET: Not Installed
                ZMQ: 4.0.4
               Mako: 0.9.1
  5. inthecloud247 commented on Dec 23, 2014

    @inthecloud247
    Contributor

    I just found that by setting the option "pillar_source_merging_strategy: aggregate" in my master.conf file, aggregation worked almost as expected. the 'reset' still didn't work entirely correctly, but it did seem better. http://docs.saltstack.com/en/latest/ref/configuration/master.html#pillar-source-merging-strategy

  6. modified the milestones: Approved, Blocked on Feb 9, 2015
  7. removed their assignment
    on Feb 9, 2015
  8. changed the title [-]yamlex !reset doesn't work in pillar config files - does work on command line[/-] [+]yamlex !reset doesn't work when combining pillars across environments[/+] on Feb 9, 2015
  9. quixoten commented on May 12, 2015

    @quixoten
    Contributor

    Running into this same issue on the latest salt when using !reset with multiple sls files. I have pillar_source_merging_strategy set to aggregate, but haven't made any other changes to the packaged /etc/salt/master. Here's what I'm trying to do:

    $ cat /srv/pillar/top.sls 
    base:
      '*':
      - defaults
      - os_family/{{ salt['grains.get']('os_family') }}
      - os_family/{{ salt['grains.get']('os_family') }}/{{ salt['grains.get']('os') }}
      - os_family/{{ salt['grains.get']('os_family') }}/{{ salt['grains.get']('os') }}/{{ salt['grains.get']('oscodename') }}
    
    $ cat /srv/pillar/defaults.sls 
    #!yamlex
    
    multiple_files: !aggregate
      - default
    
    one_file: !aggregate
      - default
    
    one_file: !aggregate
      - os_family1
      - os_family2
    
    !reset one_file: !aggregate
      - os1
    
    one_file: !aggregate
      - oscodename3
      - oscodename4
      - oscodename5
    
    $ cat /srv/pillar/os_family/Debian.sls 
    #!yamlex
    
    multiple_files: !aggregate
      - os_family1
      - os_family2
    
    $ cat /srv/pillar/os_family/Debian/Ubuntu.sls 
    #!yamlex
    
    !reset multiple_files: !aggregate
      - os1
    
    $ cat /srv/pillar/os_family/Debian/Ubuntu/trusty.sls 
    #!yamlex
    
    multiple_files: !aggregate
      - oscodename3
      - oscodename4
      - oscodename5
    

    And here's the actual result

    $ salt '*' pillar.items
    saltmaster:
        ----------
        multiple_files:
            - default
            - os_family1
            - os_family2
            - os1
            - oscodename3
            - oscodename4
            - oscodename5
        one_file:
            - os1
            - oscodename3
            - oscodename4
            - oscodename5
    

    And here's the expected result:

    $ salt '*' pillar.items
    saltmaster:
        ----------
        multiple_files:
            - os1
            - oscodename3
            - oscodename4
            - oscodename5
        one_file:
            - os1
            - oscodename3
            - oscodename4
            - oscodename5
    

    Version info:

    $ salt-call --versions
                      Salt: 2015.5.0
                    Python: 2.7.6 (default, Mar 22 2014, 22:59:56)
                    Jinja2: 2.7.2
                  M2Crypto: 0.21.1
            msgpack-python: 0.3.0
              msgpack-pure: Not Installed
                  pycrypto: 2.6.1
                   libnacl: Not Installed
                    PyYAML: 3.10
                     ioflo: Not Installed
                     PyZMQ: 14.0.1
                      RAET: Not Installed
                       ZMQ: 4.0.4
                      Mako: 0.9.1
     Debian source package: 2015.5.0+ds-1trusty1
    

    Really hoping I'm not trying to misuse this feature as I would love to have the flexibility of something like hiera without configuring an extension. It seems like I could get this working by using jinja|yamlex with jinja includes to build a single sls file. Maybe that would be a better way to go?

  10. quixoten commented on May 12, 2015

    @quixoten
    Contributor

    UPDATE: I was able to get the functionality I'm after by using jinja includes, i.e,

    $ cat /srv/pillar/top.sls 
    base:
      '*': [stack]
    
    $ cat /srv/pillar/stack.sls 
    #!jinja|yamlex
    
    {% include "defaults.sls" %}
    {% include "/".join(("os_family", grains["os_family"])) + ".sls" ignore missing %}
    {% include "/".join(("os_family", grains["os_family"], grains["os"])) + ".sls" ignore missing %}
    {% include "/".join(("os_family", grains["os_family"], grains["os"], grains["oscodename"])) + ".sls" ignore missing %}
    

    This gives the respected result, i.e.,

    $ salt '*' pillar.items
    saltmaster:
        ----------
        multiple_files:
            - os1
            - oscodename3
            - oscodename4
            - oscodename5
        one_file:
            - os1
            - oscodename3
            - oscodename4
            - oscodename5
    
  11. added
    severity-medium
    P4
    and removed
    severity-low
    on May 12, 2015
  12. added
    Core
    and removed
    Core
    on May 26, 2015
  13. stale commented on Nov 10, 2017

    @stale

    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.

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

    CoreP4Pillarbugseverity-mediumstale

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions