{"action":"created","issue":{"url":"https://api.github.com/repos/saltstack/salt/issues/47919","repository_url":"https://api.github.com/repos/saltstack/salt","labels_url":"https://api.github.com/repos/saltstack/salt/issues/47919/labels{/name}","comments_url":"https://api.github.com/repos/saltstack/salt/issues/47919/comments","events_url":"https://api.github.com/repos/saltstack/salt/issues/47919/events","html_url":"https://github.com/saltstack/salt/issues/47919","id":328464515,"node_id":"MDU6SXNzdWUzMjg0NjQ1MTU=","number":47919,"title":"Does it support grains judgment to do some operations","user":{"login":"topicgit","id":11975460,"node_id":"MDQ6VXNlcjExOTc1NDYw","avatar_url":"https://avatars2.githubusercontent.com/u/11975460?v=4","gravatar_id":"","url":"https://api.github.com/users/topicgit","html_url":"https://github.com/topicgit","followers_url":"https://api.github.com/users/topicgit/followers","following_url":"https://api.github.com/users/topicgit/following{/other_user}","gists_url":"https://api.github.com/users/topicgit/gists{/gist_id}","starred_url":"https://api.github.com/users/topicgit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/topicgit/subscriptions","organizations_url":"https://api.github.com/users/topicgit/orgs","repos_url":"https://api.github.com/users/topicgit/repos","events_url":"https://api.github.com/users/topicgit/events{/privacy}","received_events_url":"https://api.github.com/users/topicgit/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-06-01T10:25:56Z","updated_at":"2018-06-01T16:17:42Z","closed_at":null,"author_association":"NONE","body":"### Description of Issue/Question\r\nI have two computer rooms, D and E, and each machine sets up the labelling of the upper computer room through grains.\r\n\r\nNow I want to distribute different files through the computer labelling set up by grains. How should I write?\r\n\r\n\r\n### Setup\r\n(Please provide relevant configs and/or SLS files (Be sure to remove sensitive info).)\r\nsalt dd-web89-e.ld.co grains.item idc_tag\r\n```\r\ndd-web8989-e.ld.co:\r\n    ----------\r\n    idc_tag:\r\n        E\r\n\r\n{% if grains['idc_tag'] == 'E' %}\r\n/home/work/www/run/dd-web/.env:\r\n  file.managed:\r\n    - source: salt://webapps/dd-web/files/config/prod-e/.env\r\n    - makedirs: True\r\n    - user: work\r\n    - group: work\r\n{% endif %}\r\n```\r\n\r\n```\r\nsalt dd-web89-e.ld.co state.sls tmp.jiet test=True\r\ndd-web89-e.ld.co:\r\n    Data failed to compile:\r\n----------\r\n    Rendering SLS 'base:tmp.jiet' failed: Jinja variable 'dict object' has no attribute 'idc_tag'\r\n```\r\n### Steps to Reproduce Issue\r\n\r\n(Include debug logs if possible and relevant.)\r\n\r\n### Versions Report\r\n(Provided by running `salt --versions-report`. Please also mention any differences in master/minion versions.)\r\n"},"comment":{"url":"https://api.github.com/repos/saltstack/salt/issues/comments/393931030","html_url":"https://github.com/saltstack/salt/issues/47919#issuecomment-393931030","issue_url":"https://api.github.com/repos/saltstack/salt/issues/47919","id":393931030,"node_id":"MDEyOklzc3VlQ29tbWVudDM5MzkzMTAzMA==","user":{"login":"garethgreenaway","id":718525,"node_id":"MDQ6VXNlcjcxODUyNQ==","avatar_url":"https://avatars0.githubusercontent.com/u/718525?v=4","gravatar_id":"","url":"https://api.github.com/users/garethgreenaway","html_url":"https://github.com/garethgreenaway","followers_url":"https://api.github.com/users/garethgreenaway/followers","following_url":"https://api.github.com/users/garethgreenaway/following{/other_user}","gists_url":"https://api.github.com/users/garethgreenaway/gists{/gist_id}","starred_url":"https://api.github.com/users/garethgreenaway/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/garethgreenaway/subscriptions","organizations_url":"https://api.github.com/users/garethgreenaway/orgs","repos_url":"https://api.github.com/users/garethgreenaway/repos","events_url":"https://api.github.com/users/garethgreenaway/events{/privacy}","received_events_url":"https://api.github.com/users/garethgreenaway/received_events","type":"User","site_admin":false},"created_at":"2018-06-01T16:17:42Z","updated_at":"2018-06-01T16:17:42Z","author_association":"MEMBER","body":"@topicgit Thanks for the report.  What you have above should work, I'd suspect that something isn't synced up and when you're running the state run the grains are not available.  A safer approach would be the following:\r\n```\r\n{% if salt['grains.get']('idc_tag', '') == 'E' %}\r\n/home/work/www/run/dd-web/.env:\r\n  file.managed:\r\n    - source: salt://webapps/dd-web/files/config/prod-e/.env\r\n    - makedirs: True\r\n    - user: work\r\n    - group: work\r\n{% endif %}\r\n```\r\nThis approach is calling out to the `get` function in the `grains` module but also includes a default value in the event that the grain value is unable."}}
{"actor":{"display_login":"garethgreenaway"}}