{"action":"opened","issue":{"url":"https://api.github.com/repos/saltstack/salt/issues/20010","labels_url":"https://api.github.com/repos/saltstack/salt/issues/20010/labels{/name}","comments_url":"https://api.github.com/repos/saltstack/salt/issues/20010/comments","events_url":"https://api.github.com/repos/saltstack/salt/issues/20010/events","html_url":"https://github.com/saltstack/salt/issues/20010","id":55319707,"number":20010,"title":"Include State only if it exists","user":{"login":"puneetk","id":528061,"avatar_url":"https://avatars.githubusercontent.com/u/528061?v=3","gravatar_id":"","url":"https://api.github.com/users/puneetk","html_url":"https://github.com/puneetk","followers_url":"https://api.github.com/users/puneetk/followers","following_url":"https://api.github.com/users/puneetk/following{/other_user}","gists_url":"https://api.github.com/users/puneetk/gists{/gist_id}","starred_url":"https://api.github.com/users/puneetk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/puneetk/subscriptions","organizations_url":"https://api.github.com/users/puneetk/orgs","repos_url":"https://api.github.com/users/puneetk/repos","events_url":"https://api.github.com/users/puneetk/events{/privacy}","received_events_url":"https://api.github.com/users/puneetk/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-01-23T19:10:11Z","updated_at":"2015-01-23T19:10:11Z","closed_at":null,"body":"Hi,\r\nI would like to be able to include an sls file only if it exists. The use case for this came up when working with [Collectd saltstack formula pillar](https://github.com/saltstack-formulas/collectd-formula/blob/master/pillar.example), and the way the formula is setup. What i would like to do is include the collectd formula in my top.sls file and then use the pillar to configure what states get included from the formula. \r\n\r\nFor eg the collectd/init.sls file would look like \r\n```saltstack\r\ninclude:\r\n  - collectd.package\r\n  - collectd.service\r\n  {% for state in salt['pillar.get']('collectd:plugins:enabled') %}\r\n  - collectd.{{state}}\r\n  {% endfor %} \r\n```\r\nAnd the corresponding pillar would be \r\n```saltstack\r\ncollectd:\r\n  FQDNLookup: true\r\n  TypesDB: ['/usr/share/collectd/types.db']\r\n  plugins: \r\n    enabled: [battery, cpu, entropy, load, memory, swap, users, write_graphite ]\r\n```\r\nNow this would require that we have states for each plugin that is enabled. Instead if i could do the following, I can now make extra configs for the plugins, if needed and include the one file in the top.sls by enabling the collectd plugin in a pillar. \r\n```saltstack\r\ninclude:\r\n  - collectd.package\r\n  - collectd.service\r\ninclude_if_exists:\r\n  {% for state in salt['pillar.get']('collectd:plugins:enabled') %}\r\n  - collectd.{{state}}\r\n  {% endfor %} \r\n```\r\nCurrently i would have to make two pillars and then iterate over them separately. \r\n\r\n\r\n"}}