{"action":"created","issue":{"url":"https://api.github.com/repos/saltstack/salt/issues/28351","labels_url":"https://api.github.com/repos/saltstack/salt/issues/28351/labels{/name}","comments_url":"https://api.github.com/repos/saltstack/salt/issues/28351/comments","events_url":"https://api.github.com/repos/saltstack/salt/issues/28351/events","html_url":"https://github.com/saltstack/salt/issues/28351","id":113806685,"number":28351,"title":"Skip Set of States when a cmd exits non-zero","user":{"login":"srkunze","id":1389648,"avatar_url":"https://avatars.githubusercontent.com/u/1389648?v=3","gravatar_id":"","url":"https://api.github.com/users/srkunze","html_url":"https://github.com/srkunze","followers_url":"https://api.github.com/users/srkunze/followers","following_url":"https://api.github.com/users/srkunze/following{/other_user}","gists_url":"https://api.github.com/users/srkunze/gists{/gist_id}","starred_url":"https://api.github.com/users/srkunze/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/srkunze/subscriptions","organizations_url":"https://api.github.com/users/srkunze/orgs","repos_url":"https://api.github.com/users/srkunze/repos","events_url":"https://api.github.com/users/srkunze/events{/privacy}","received_events_url":"https://api.github.com/users/srkunze/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/saltstack/salt/labels/Pending%20Discussion","name":"Pending Discussion","color":"c7def8"},{"url":"https://api.github.com/repos/saltstack/salt/labels/Question","name":"Question","color":"942192"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/saltstack/salt/milestones/37","html_url":"https://github.com/saltstack/salt/milestones/Blocked","labels_url":"https://api.github.com/repos/saltstack/salt/milestones/37/labels","id":343741,"number":37,"title":"Blocked","description":"Issues which are blocked in some way, whether they need further discussion, clarification, justification, or are blocked for some other reason.","creator":{"login":"basepi","id":702318,"avatar_url":"https://avatars.githubusercontent.com/u/702318?v=3","gravatar_id":"","url":"https://api.github.com/users/basepi","html_url":"https://github.com/basepi","followers_url":"https://api.github.com/users/basepi/followers","following_url":"https://api.github.com/users/basepi/following{/other_user}","gists_url":"https://api.github.com/users/basepi/gists{/gist_id}","starred_url":"https://api.github.com/users/basepi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/basepi/subscriptions","organizations_url":"https://api.github.com/users/basepi/orgs","repos_url":"https://api.github.com/users/basepi/repos","events_url":"https://api.github.com/users/basepi/events{/privacy}","received_events_url":"https://api.github.com/users/basepi/received_events","type":"User","site_admin":false},"open_issues":323,"closed_issues":667,"state":"open","created_at":"2013-05-28T22:24:12Z","updated_at":"2015-11-03T17:19:46Z","due_on":null,"closed_at":null},"comments":3,"created_at":"2015-10-28T12:08:30Z","updated_at":"2015-11-03T17:33:41Z","closed_at":null,"body":"Imagine I have n states and I would like to skip them altogether. The `unless` clause might be a solution. The issue with `unless` is that I need to repeat the cmd n times.\r\n\r\nThat has several drawbacks:\r\n  - code cleanliness and maintainability\r\n  - execution time (in our case cmd takes several seconds to complete)\r\n\r\nYou might ask, why not using a `{% if %}` to prevent the execution of the states in the first place? Because, before the execution of the cmd, several other states need to be applied in order for the cmd to work properly.\r\n\r\n\r\nIs there an existing solution I am missing?"},"comment":{"url":"https://api.github.com/repos/saltstack/salt/issues/comments/153426973","html_url":"https://github.com/saltstack/salt/issues/28351#issuecomment-153426973","issue_url":"https://api.github.com/repos/saltstack/salt/issues/28351","id":153426973,"user":{"login":"basepi","id":702318,"avatar_url":"https://avatars.githubusercontent.com/u/702318?v=3","gravatar_id":"","url":"https://api.github.com/users/basepi","html_url":"https://github.com/basepi","followers_url":"https://api.github.com/users/basepi/followers","following_url":"https://api.github.com/users/basepi/following{/other_user}","gists_url":"https://api.github.com/users/basepi/gists{/gist_id}","starred_url":"https://api.github.com/users/basepi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/basepi/subscriptions","organizations_url":"https://api.github.com/users/basepi/orgs","repos_url":"https://api.github.com/users/basepi/repos","events_url":"https://api.github.com/users/basepi/events{/privacy}","received_events_url":"https://api.github.com/users/basepi/received_events","type":"User","site_admin":false},"created_at":"2015-11-03T17:33:41Z","updated_at":"2015-11-03T17:33:41Z","body":"The only way that currently exists is to put a `require` requisite on each of those states, pointing to the cmd which you're monitoring, which, by default, will fail on a non-zero exit code. If that state fails, all the states that require it will be skipped.\r\n\r\nGranted, this will result in \"failed\" states in your output, but there are only two things we can cue off of in the state system anyway -- changes, and failures.\r\n\r\nAnother option that is a little harder to implement but will be cleaner in the end is to make the command in question a custom state module. If the command succeeds, make sure the Changes dictionary is empty. If the command exits with a non-zero code, put something in the Changes dictionary. You could then use `onchanges` on all your skippable states, so they will only run when there are changes in your command state, which will only have changes on a non-zero exit code.\r\n\r\nDoes that make sense?"}}