Skip to content

'Smart' pillar_source_merging_strategy does not use aggregate for yamlex #26396

Closed

Description

@carlpett

I'm trying to use #!yamlex and !aggregate in some of my pillar files. As I understand the documentation of pillar_source_merging_strategy, the default 'smart' strategy should then switch to the aggregate when it finds a yamlex renderer. However, it doesn't. If I set the merge strategy to aggregate in the master config, it does work.

I've created files like this:

pillar/top.sls
'test-node':
  - merging.testbase
  - merging.test1
  - merging.test2
pillar/merging/testbase.sls
#!yamlex
foo: !aggregate baz
foo: !aggregate base
pillar/merging/test1.sls
#!yamlex
foo: !aggregate bar
pillar/merging/test2.sls
#!yamlex
foo: !aggregate qux
# salt-call --local pillar.items foo
local:
    ----------
    foo:
        - qux

Am I misunderstanding the documentation when I think that the smart strategy should switch to aggregate here, or is this a bug?

# salt --versions-report
           Salt: 2015.5.3
         Python: 2.7.5 (default, Jun 17 2014, 18:11:42)
         Jinja2: 2.8
       M2Crypto: 0.21.1
 msgpack-python: 0.4.2
   msgpack-pure: Not Installed
       pycrypto: 2.6.1
        libnacl: Not Installed
         PyYAML: 3.10
          ioflo: Not Installed
          PyZMQ: 14.3.1
           RAET: Not Installed
            ZMQ: 3.2.4
           Mako: Not Installed
        Tornado: Not Installed

Activity

  1. added
    bug
    severity-medium
    Core
    P3
    on Aug 17, 2015
  2. added this to the Approved milestone on Aug 17, 2015
  3. jfindlay commented on Aug 17, 2015

    @jfindlay
    Contributor

    @carlpett, thanks for the report.

  4. mchugh19 commented on Jun 7, 2017

    @mchugh19
    Contributor

    This still seems to be the case.

    # salt --versions
    Salt Version:
               Salt: 2016.11.4
    
    Dependency Versions:
               cffi: 1.6.0
           cherrypy: unknown
           dateutil: 2.6.0
          docker-py: Not Installed
              gitdb: Not Installed
          gitpython: Not Installed
              ioflo: Not Installed
             Jinja2: 2.7.2
            libgit2: 0.21.4
            libnacl: Not Installed
           M2Crypto: Not Installed
               Mako: Not Installed
       msgpack-pure: Not Installed
     msgpack-python: 0.4.8
       mysql-python: Not Installed
          pycparser: 2.17
           pycrypto: 2.6.1
       pycryptodome: 3.4.3
             pygit2: 0.21.4
             Python: 2.7.5 (default, Nov  6 2016, 00:28:07)
       python-gnupg: Not Installed
             PyYAML: 3.11
              PyZMQ: 15.3.0
               RAET: Not Installed
              smmap: Not Installed
            timelib: Not Installed
            Tornado: 4.2.1
                ZMQ: 4.1.4
    
    System Versions:
               dist: centos 7.3.1611 Core
            machine: x86_64
            release: 3.10.0-514.16.1.el7.x86_64
             system: Linux
            version: CentOS Linux 7.3.1611 Core
    

    Here are the results for the default smart merging strategy. Here zabbix-agent has a bunch of keys and values, and testkey and testlist that are using yamlex aggregates for the list. The testlist pillar is not rendered properly, and seems to be using the overwrite strategy.

    # salt-call pillar.items
        testkey:
            test2
        testlist:
            - test2
        zabbix-agent:
            ----------
            include:
                /etc/zabbix/zabbix_agentd.d/
            listenip:
                0.0.0.0
            listenport:
                10050
            logfile:
                /var/log/zabbix/zabbix_agentd.log
            logfilesize:
                0
            timeout:
                25
            userparameters:
                - vaulttoken.ttl,/usr/local/bin/vault-ttl.py
    

    If the master.conf is updated to explicitly use the aggregate strategy, then the testlist is properly rendered, but the normal zabbix-agent keys and values are missing (expected as not all parts of that key use yamlex aggregate):

        testkey:
            test2
        testlist:
            - test1
            - test2
        zabbix-agent:
            ----------
            userparameters:
                - vaulttoken.ttl,/usr/local/bin/vault-ttl.py
    
  5. mchugh19 commented on Jun 7, 2017

    @mchugh19
    Contributor

    In this state, it seems the only way to have merged lists is to use the pillar_merge_lists option. However, this isn't quite optimal as this is a global setting for all lists. Aggregate seems to be the only pillar option allowing list merge while not merging for all lists, but as shown seems to break non aggregate pillars.

  6. mchugh19 commented on Jun 8, 2017

    @mchugh19
    Contributor

    In #18665 it was mentioned that using a jinja include made the smart render function as expected: #!jinja|yamlex With that, my test pillars are rendered properly when master has pillar_merge_lists enabled. With pillar_merge_lists disabled, the testlist item only includes the test2 entry.

        testkey:
            test2
        testlist:
            - test1
            - test2
        zabbix-agent:
            ----------
            include:
                /etc/zabbix/zabbix_agentd.d/
            listenip:
                0.0.0.0
            listenport:
                10050
            logfile:
                /var/log/zabbix/zabbix_agentd.log
            logfilesize:
                0
            timeout:
                25
            userparameters:
                - vaulttoken.ttl,/usr/local/bin/vault-ttl.py
    
  7. mchugh19 commented on Jun 13, 2017

    @mchugh19
    Contributor

    A few tests seem to show that the smart merging strategy simply isn't operational for yamlex (which makes it seem like yamlex isn't functional so all of this is begging for unit tests)

    In utils/dictupdate.py, I added a few logging lines:

    def merge(obj_a, obj_b, strategy='smart', renderer='yaml', merge_lists=False):
        if strategy == 'smart':
            log.info('Using strategy {0} with renderer {1}'.format(strategy, renderer))
    

    This prints:

    [INFO    ][18338] Using strategy smart with renderer yaml
    [INFO    ][18338] Using strategy smart with renderer yaml_jinja
    

    But this is a problem as I have a few pillar files such as:

    ==> test1.sls <==
    #!yamlex
    testkey: test1
    testlist: !aggregate test1
    ==> test2.sls <==
    #!yamlex
    testkey: test2
    testlist: !aggregate test2
    

    From these, I would expect to see a yamlex renderer logged, but I do not.

    Updating the the merge(... renderer=yamlex default causes the print to see the expected log items:

    [salt.utils.dictupdate][INFO    ][22046] Using strategy smart with renderer yamlex
    [salt.utils.dictupdate][INFO    ][22047] Using strategy smart with renderer yaml_jinja
    [salt.utils.dictupdate][INFO    ][22047] Using strategy smart with renderer yaml_jinja
    [salt.utils.dictupdate][INFO    ][22047] Using strategy smart with renderer yamlex
    [salt.utils.dictupdate][INFO    ][22047] Using strategy smart with renderer yaml_jinja
    

    But this still doesn't seem to use the yamlex behavior. So yamlex seems pretty broken at the moment.

  8. mchugh19 commented on Jun 19, 2017

    @mchugh19
    Contributor

    @rallytime or @cachedout is there anyone that could provide a comment hint for where to start investigating this issue? It currently appears that yamlex simply isn't working as designed with either the smart pillar merge strategy or simple aggregation.

    As far as I know, this is the only mechanism salt possesses that could allow for pillar setting/merging/overriding with a distributed pillar environment (multiple git_pillar repos managed by layers of different support teams) and could be crucial for distributed management in an enterprise environment.

  9. rallytime commented on Jun 19, 2017

    @rallytime
    Contributor

    I think @terminalmage would be the best one to comment on this issue or talk to about troubleshooting this.

    @terminalmage Do you have any feedback on this since you were recently in the pillar merge strategy code somewhat recently?

  10. mattp- commented on Apr 15, 2018

    @mattp-
    Contributor

    @carlpett just encountered this myself, it seems the 'renderer' that is used to control the merging strategy inside the 'smart' strategy is the default. so if you set master: renderer: yamlex_jinja it will behave how you expect. This is not obvious at all though, so I'll send in a doc patch to note it.

  11. 14 remaining items

  12. stale commented on Jan 8, 2020

    @stale

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

  13. removed
    P3
    on Jun 3, 2020
  14. terminalmage commented on Jan 18, 2021

    @terminalmage
    Contributor

    From the documentation:

    Guesses the best strategy based on the "renderer" setting
    

    This refers to the renderer master config option. You'll need to set it to something like jinja|yamlex for this to work.

    The documentation does incorrectly suggest that you can just use a !yamlex shebang, which is not true. I've fixed this with a documentation update in #59317.

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

Metadata

Metadata

Assignees

Labels

AluminiumConfirmedCorePillarbugseverity-medium

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions