{"action":"created","issue":{"url":"https://api.github.com/repos/saltstack/salt/issues/34433","repository_url":"https://api.github.com/repos/saltstack/salt","labels_url":"https://api.github.com/repos/saltstack/salt/issues/34433/labels{/name}","comments_url":"https://api.github.com/repos/saltstack/salt/issues/34433/comments","events_url":"https://api.github.com/repos/saltstack/salt/issues/34433/events","html_url":"https://github.com/saltstack/salt/issues/34433","id":163462208,"number":34433,"title":"2016.3.1  grain value in jinja is empty while has a value when requested on the CLI","user":{"login":"UtahDave","id":306240,"avatar_url":"https://avatars.githubusercontent.com/u/306240?v=3","gravatar_id":"","url":"https://api.github.com/users/UtahDave","html_url":"https://github.com/UtahDave","followers_url":"https://api.github.com/users/UtahDave/followers","following_url":"https://api.github.com/users/UtahDave/following{/other_user}","gists_url":"https://api.github.com/users/UtahDave/gists{/gist_id}","starred_url":"https://api.github.com/users/UtahDave/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/UtahDave/subscriptions","organizations_url":"https://api.github.com/users/UtahDave/orgs","repos_url":"https://api.github.com/users/UtahDave/repos","events_url":"https://api.github.com/users/UtahDave/events{/privacy}","received_events_url":"https://api.github.com/users/UtahDave/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-07-01T19:43:35Z","updated_at":"2016-07-01T19:52:35Z","closed_at":null,"body":"### Description of Issue/Question\r\nWhen I run `salt '<minion id>' grains.get 'ip4_interfaces:eth1' ` on the salt master I get a value back. When I make the same call within a jinja managed file I get an empty list.\r\n\r\n### Setup\r\ncat /srv/salt/pkgrepo/apache/init.sls\r\n```\r\nhttpd_stuff:\r\n  pkg.installed:\r\n    - pkgs:\r\n      - httpd\r\n      - mod_ssl\r\n  file.managed:\r\n    - name: /etc/httpd/conf/httpd.conf\r\n    - source: salt://pkgrepo/apache/httpd.conf\r\n    - template: jinja\r\n    - user: root\r\n    - group: root\r\n    - mode: 644\r\n```\r\n\r\ncat /srv/salt/pkgrepo/apache/httpd.conf\r\n\r\n```\r\n<-- snip -->\r\n\r\nListen {{ salt['grains.get']('ip4_interfaces:eth1').pop() }}:80\r\n\r\n<-- snip -->\r\n\r\n```\r\n\r\n\r\n\r\n### Steps to Reproduce Issue\r\n\r\n```\r\n[root@qa-master ~]# salt '*backend03' grains.get 'ip4_interfaces:eth1'\r\npkgrepo-backend03:\r\n    - 10.xxx.xxx.xxx\r\n```\r\n\r\n```\r\n[root@qa-master ~]# salt '*backend03' state.sls pkgrepo.apache\r\npkgrepo-backend03:\r\n----------\r\n          ID: httpd_stuff\r\n    Function: pkg.installed\r\n      Result: True\r\n     Comment: All specified packages are already installed\r\n     Started: 15:39:46.112488\r\n    Duration: 1717.498 ms\r\n     Changes:   \r\n----------\r\n          ID: httpd_stuff\r\n    Function: file.managed\r\n        Name: /etc/httpd/conf/httpd.conf\r\n      Result: False\r\n     Comment: Unable to manage file: Jinja error: pop from empty list\r\n              Traceback (most recent call last):\r\n                File \"/usr/lib/python2.7/site-packages/salt/utils/templates.py\", line 366, in render_jinja_tmpl\r\n                  output = template.render(**decoded_context)\r\n                File \"/usr/lib/python2.7/site-packages/jinja2/environment.py\", line 969, in render\r\n                  return self.environment.handle_exception(exc_info, True)\r\n                File \"/usr/lib/python2.7/site-packages/jinja2/environment.py\", line 742, in handle_exception\r\n                  reraise(exc_type, exc_value, tb)\r\n                File \"<template>\", line 43, in top-level template code\r\n              IndexError: pop from empty list\r\n              \r\n              ; line 43\r\n              \r\n              ---\r\n              [...]\r\n              # Change this to Listen on specific IP addresses as shown below to \r\n              # prevent Apache from glomming onto all bound IP addresses.\r\n              #\r\n              \r\n              #Listen 80\r\n              Listen {{ salt['grains.get']('ip4_interfaces:eth1').pop() }}:80    <======================\r\n              \r\n              #\r\n              # Dynamic Shared Object (DSO) Support\r\n              #\r\n              # To be able to use the functionality of a module which was built as a DSO you\r\n              [...]\r\n              ---\r\n     Started: 15:39:47.833510\r\n    Duration: 306.052 ms\r\n     Changes:   \r\n```\r\n\r\n\r\n### Versions Report\r\n```\r\n[root@qa-master ~]# salt '*backend03' test.versions_report\r\npkgrepo-backend03:\r\n    Salt Version:\r\n               Salt: 2016.3.1\r\n     \r\n    Dependency Versions:\r\n               cffi: Not Installed\r\n           cherrypy: Not Installed\r\n           dateutil: Not Installed\r\n              gitdb: Not Installed\r\n          gitpython: Not Installed\r\n              ioflo: Not Installed\r\n             Jinja2: 2.7.2\r\n            libgit2: Not Installed\r\n            libnacl: Not Installed\r\n           M2Crypto: 0.21.1\r\n               Mako: Not Installed\r\n       msgpack-pure: Not Installed\r\n     msgpack-python: 0.4.7\r\n       mysql-python: Not Installed\r\n          pycparser: Not Installed\r\n           pycrypto: 2.6.1\r\n             pygit2: Not Installed\r\n             Python: 2.7.5 (default, Nov 20 2015, 02:00:19)\r\n       python-gnupg: Not Installed\r\n             PyYAML: 3.11\r\n              PyZMQ: 14.7.0\r\n               RAET: Not Installed\r\n              smmap: Not Installed\r\n            timelib: Not Installed\r\n            Tornado: 4.2.1\r\n                ZMQ: 4.0.5\r\n     \r\n    System Versions:\r\n               dist: centos 7.2.1511 Core\r\n            machine: x86_64\r\n            release: 3.10.0-123.8.1.el7.x86_64\r\n             system: Linux\r\n            version: CentOS Linux 7.2.1511 Core\r\n```"},"comment":{"url":"https://api.github.com/repos/saltstack/salt/issues/comments/230034041","html_url":"https://github.com/saltstack/salt/issues/34433#issuecomment-230034041","issue_url":"https://api.github.com/repos/saltstack/salt/issues/34433","id":230034041,"user":{"login":"UtahDave","id":306240,"avatar_url":"https://avatars.githubusercontent.com/u/306240?v=3","gravatar_id":"","url":"https://api.github.com/users/UtahDave","html_url":"https://github.com/UtahDave","followers_url":"https://api.github.com/users/UtahDave/followers","following_url":"https://api.github.com/users/UtahDave/following{/other_user}","gists_url":"https://api.github.com/users/UtahDave/gists{/gist_id}","starred_url":"https://api.github.com/users/UtahDave/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/UtahDave/subscriptions","organizations_url":"https://api.github.com/users/UtahDave/orgs","repos_url":"https://api.github.com/users/UtahDave/repos","events_url":"https://api.github.com/users/UtahDave/events{/privacy}","received_events_url":"https://api.github.com/users/UtahDave/received_events","type":"User","site_admin":false},"created_at":"2016-07-01T19:52:35Z","updated_at":"2016-07-01T19:52:35Z","body":"@whiteinge asked me to test if the `grains.get` works in the sls file directly and it does.\r\n\r\nI changed to this:\r\n\r\n```\r\nhttpd_stuff:\r\n  pkg.installed:\r\n    - pkgs:\r\n      - httpd\r\n      - mod_ssl\r\n  file.managed:\r\n    - name: /etc/httpd/conf/httpd.conf\r\n    - source: salt://pkgrepo/apache/httpd.conf\r\n    - template: jinja\r\n    - user: root\r\n    - group: root\r\n    - mode: 644\r\n    - mystuff: {{ salt['grains.get']('ip4_interfaces:eth1').pop() }}\r\n```\r\nand  mystuff was assigned the ip address as the value correctly\r\n"}}
{"actor":{"display_login":"UtahDave"}}