{"action":"created","issue":{"url":"https://api.github.com/repos/ansible/ansible/issues/10085","repository_url":"https://api.github.com/repos/ansible/ansible","labels_url":"https://api.github.com/repos/ansible/ansible/issues/10085/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible/issues/10085/comments","events_url":"https://api.github.com/repos/ansible/ansible/issues/10085/events","html_url":"https://github.com/ansible/ansible/pull/10085","id":55404416,"number":10085,"title":"allow missing subelement keywords to be optionally ignored","user":{"login":"aks","id":3990,"avatar_url":"https://avatars.githubusercontent.com/u/3990?v=3","gravatar_id":"","url":"https://api.github.com/users/aks","html_url":"https://github.com/aks","followers_url":"https://api.github.com/users/aks/followers","following_url":"https://api.github.com/users/aks/following{/other_user}","gists_url":"https://api.github.com/users/aks/gists{/gist_id}","starred_url":"https://api.github.com/users/aks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aks/subscriptions","organizations_url":"https://api.github.com/users/aks/orgs","repos_url":"https://api.github.com/users/aks/repos","events_url":"https://api.github.com/users/aks/events{/privacy}","received_events_url":"https://api.github.com/users/aks/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ansible/ansible/labels/feature_pull_request","name":"feature_pull_request","color":"009800"},{"url":"https://api.github.com/repos/ansible/ansible/labels/needs_rebase","name":"needs_rebase","color":"eb6420"},{"url":"https://api.github.com/repos/ansible/ansible/labels/pending_action","name":"pending_action","color":"e11d21"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":14,"created_at":"2015-01-25T08:10:17Z","updated_at":"2016-03-18T17:42:02Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ansible/ansible/pulls/10085","html_url":"https://github.com/ansible/ansible/pull/10085","diff_url":"https://github.com/ansible/ansible/pull/10085.diff","patch_url":"https://github.com/ansible/ansible/pull/10085.patch"},"body":"This request is a simple change to `subelements.py` and `constants.py`, which allows the user to optionally ignore missing keywords on a `with_subelements` loop.  The change is a new configuration item: `ignore_missing_subelements`, and the logic to use the variable in `subelements.py`.\r\n\r\nThe default for this config variable is false, which causes the code in `subelements.py` to behave as usual and raise an error when subelement keywords are missing.  The default behavior is less flexible, but since some users may have written their playbooks or roles to depend on this, we leave it as the default.\r\n\r\nHowever, the more flexible -- and typical -- usage of this feature will be to have `ignore_missing_subelements` set to true, which allows for flexible data patterns in the application of tasks looping with `with_subelements`.  The items for which there is no corresponding key are simply ignored.\r\n\r\nAt our site, this feature is important (and in use) for using ansible in managing keys in our user's `authorized_keys` file, in that (a) not all of our users have the same number of ssh keys, and (b) some of our users have no ssh key.\r\n"},"comment":{"url":"https://api.github.com/repos/ansible/ansible/issues/comments/198466585","html_url":"https://github.com/ansible/ansible/pull/10085#issuecomment-198466585","issue_url":"https://api.github.com/repos/ansible/ansible/issues/10085","id":198466585,"user":{"login":"aks","id":3990,"avatar_url":"https://avatars.githubusercontent.com/u/3990?v=3","gravatar_id":"","url":"https://api.github.com/users/aks","html_url":"https://github.com/aks","followers_url":"https://api.github.com/users/aks/followers","following_url":"https://api.github.com/users/aks/following{/other_user}","gists_url":"https://api.github.com/users/aks/gists{/gist_id}","starred_url":"https://api.github.com/users/aks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aks/subscriptions","organizations_url":"https://api.github.com/users/aks/orgs","repos_url":"https://api.github.com/users/aks/repos","events_url":"https://api.github.com/users/aks/events{/privacy}","received_events_url":"https://api.github.com/users/aks/received_events","type":"User","site_admin":false},"created_at":"2016-03-18T17:42:02Z","updated_at":"2016-03-18T17:42:02Z","body":"@bcoca, the case for exactly conforming data is apparently much less frequent than the case for flexibly matching the data that is available.  So, all things being equal, it would seem logical to make the default case be the common and more flexible case of skipping missing sub-elements silently.\r\n\r\nWe can, as suggested, create an option to `with-subelements` that can cause either failures on missing sub-elements, or silence on them.  If the default were configurable, then both options would be required, because otherwise, how would a playbook be written to operate consistently, regardless of configuration?\r\n\r\nAnother, less-verbose way than using options the existing iterator, is to create new, more specific iterators: `with-optional-subelements` and `with-required-subelements`.  This avoids the use of options, and makes the playbook design explicit with consistent behavior.\r\n\r\nIf there is general agreement, I'll volunteer some time to code up both of these new iterators for ansible2, and submit for review."}}