salt: salt.states.grains.list_present adds duplicates names

Hi,

I noticed that using the ‘grains’ state multiple times results in duplicate list items. One would expect that the grains state immediately updates the roles grains after modifying it.

For example this state

# set roles
roles-nginx:
  grains.list_present:
    - name: roles
    - value:
      - webserver
      - webserver-nginx
    - require:
      - service: nginx-service

roles-nginx-php-fpm:
  grains.list_present:
    - name: roles
    - value:
      - php
      - php-fpm
      - webserver
      - webserver-nginx
      - webserver-nginx-php-fpm

yields this result

zsh 386 # salt minion grains.item roles
minion:
    ----------
    roles:
        - webserver
        - webserver-nginx
        - php
        - php-fpm
        - webserver
        - webserver-nginx
        - webserver-nginx-php-fpm

Is this a bug or a feature? It feels wrong to force a grain update in the state file?

About this issue

  • Original URL
  • State: open
  • Created 8 years ago
  • Reactions: 1
  • Comments: 16 (11 by maintainers)

Commits related to this issue

Most upvoted comments

This is a legit bug and should be fixable in minutes

@githubcdr, I get the following results on 2015.8.3 and 2015.8.7.

jmoney-main ~ master # cat /srv/salt/test.sls
roles:
  grains.list_present:
    - name: roles
    - value:
      - elliptic
      - parabolic
      - hyperbolic

additional-roles:
  grains.list_present:
    - name: roles
    - value:
      - hyperbolic
      - diabolic
jmoney-main ~ master # salt jmoney-main state.show_sls test
jmoney-main:
    ----------
    additional-roles:
        ----------
        __env__:
            base
        __sls__:
            test
        grains:
            |_
              ----------
              name:
                  roles
            |_
              ----------
              value:
                  - hyperbolic
                  - diabolic
            - list_present
            |_
              ----------
              order:
                  10001
    roles:
        ----------
        __env__:
            base
        __sls__:
            test
        grains:
            |_
              ----------
              name:
                  roles
            |_
              ----------
              value:
                  - elliptic
                  - parabolic
                  - hyperbolic
            - list_present
            |_
              ----------
              order:
                  10000
jmoney-main ~ master # salt jmoney-main state.apply test
jmoney-main:
----------
          ID: roles
    Function: grains.list_present
      Result: True
     Comment: Append value ['elliptic', 'parabolic', 'hyperbolic'] to grain roles
     Started: 12:20:47.135999
    Duration: 200.115 ms
     Changes:
              ----------
              new:
                  ----------
                  roles:
                      - elliptic
                      - parabolic
                      - hyperbolic
                      - hyperbolic
                      - diabolic
----------
          ID: additional-roles
    Function: grains.list_present
        Name: roles
      Result: True
     Comment: Append value ['hyperbolic', 'diabolic'] to grain roles
     Started: 12:20:47.336386
    Duration: 83.804 ms
     Changes:
              ----------
              new:
                  ----------
                  roles:
                      - elliptic
                      - parabolic
                      - hyperbolic
                      - hyperbolic
                      - diabolic

Summary for jmoney-main
------------
Succeeded: 2 (changed=2)
Failed:    0
------------
Total states run:     2
Total run time: 283.919 ms
jmoney-main ~ master # salt jmoney-main grains.item roles
jmoney-main:
    ----------
    roles:
        - elliptic
        - parabolic
        - hyperbolic
        - hyperbolic
        - diabolic