saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Install Salt from the Salt package repositories here:
https://docs.saltproject.io/salt/install-guide/en/latest/
Apache License 2.0
14.18k stars 5.48k forks source link

Pillar states no longer properly execute salt functions in 2014.1.1 #11453

Closed erenfro closed 10 years ago

erenfro commented 10 years ago

This is similar to https://github.com/saltstack/salt/issues/10954

I have in my /etc/salt/grains:

roles:
  - default
  - timeserver
  - hypervisor
datacenter: home

on nodes hv1, and hv2.

I have an ntp pillar that fails this segment and instead provides the data in else:

ntp:
  {# ## Assign NTP Servers Based On Environment ## #}
  {% if 'timeserver' in grains['roles'] %}
  {% if grains['id'] == 'hv1.home.ld' %}
  ntpservers: 
    - 0.us.pool.ntp.org iburst
    - 1.us.pool.ntp.org iburst
    - 2.us.pool.ntp.org iburst
    - 3.us.pool.ntp.org iburst
  comment: ''                      

  {# Secondary NTP Servers Get Data From Primary #}
  {% elif grains['id'] == 'hv2.home.ld' %}
  ntpservers:
    - hv1.home.ld iburst prefer true
    - 0.us.pool.ntp.org iburst
    - 1.us.pool.ntp.org iburst
    - 2.us.pool.ntp.org iburst
    - 3.us.pool.ntp.org iburst
  comment: ''

  {% endif %}
  {# Otherwise This Is Just An Internal Box #}
  {% else %}
  comment: '#'

  ntpservers: 
    - hv1.home.ld prefer
    - hv2.home.ld prefer
  {% endif %}

  {# ### Network #}
  {% if 'home' in salt['grains.get']('datacenter', []) %}
  {# if 'home' in grains['datacenter'] #}
  localnetworks:
    - 172.17.0.0 mask 255.255.0.0
  {% else %}
  localnetworks:
    - 172.17.0.0 mask 255.255.0.0
  {% endif %}

If I use grains['roles'] it works, but salt['grains.get']('roles', []) fails. This functionally worked in 0.17.1-0.17.4, and only upgrading to 2014.1.1 causes this to fail, completely changing several things that have been using the more reliable grains.get method!

basepi commented 10 years ago

Can reproduce. The method is working on the command line, but failing in pillar SLS files.

top.sls:

base:
  '*':
    - test

test.sls:

mypillar: {{ salt['grains.get']('server_id', []) }}

mypillar gets set to 0 for me, when it should be the server_id (1670551073 in this case) or an empty list.

cachedout commented 10 years ago

The above PR fixes this issue in my testing. I have labeled this bug as Fixed and also as Needs Testing. Pinging @rallytime for some QA here to prevent regressions.

s0undt3ch commented 10 years ago

Reopened because 8ac3aad was revert for now.

s0undt3ch commented 10 years ago

http://jenkins.saltstack.com/job/salt-rs-arch/2410/testReport/junit/unit.pillar_test/PillarTestCase/test_topfile_order/