{"action":"created","issue":{"url":"https://api.github.com/repos/ansible/ansible/issues/12577","repository_url":"https://api.github.com/repos/ansible/ansible","labels_url":"https://api.github.com/repos/ansible/ansible/issues/12577/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible/issues/12577/comments","events_url":"https://api.github.com/repos/ansible/ansible/issues/12577/events","html_url":"https://github.com/ansible/ansible/issues/12577","id":109154542,"number":12577,"title":"ansible_become cannot be overriden by host or task. local_action and delegate_to both affected","user":{"login":"caylorme","id":4383446,"avatar_url":"https://avatars.githubusercontent.com/u/4383446?v=3","gravatar_id":"","url":"https://api.github.com/users/caylorme","html_url":"https://github.com/caylorme","followers_url":"https://api.github.com/users/caylorme/followers","following_url":"https://api.github.com/users/caylorme/following{/other_user}","gists_url":"https://api.github.com/users/caylorme/gists{/gist_id}","starred_url":"https://api.github.com/users/caylorme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caylorme/subscriptions","organizations_url":"https://api.github.com/users/caylorme/orgs","repos_url":"https://api.github.com/users/caylorme/repos","events_url":"https://api.github.com/users/caylorme/events{/privacy}","received_events_url":"https://api.github.com/users/caylorme/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ansible/ansible/labels/bug_report","name":"bug_report","color":"fbca04"}],"state":"open","locked":false,"assignee":{"login":"bcoca","id":836171,"avatar_url":"https://avatars.githubusercontent.com/u/836171?v=3","gravatar_id":"","url":"https://api.github.com/users/bcoca","html_url":"https://github.com/bcoca","followers_url":"https://api.github.com/users/bcoca/followers","following_url":"https://api.github.com/users/bcoca/following{/other_user}","gists_url":"https://api.github.com/users/bcoca/gists{/gist_id}","starred_url":"https://api.github.com/users/bcoca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bcoca/subscriptions","organizations_url":"https://api.github.com/users/bcoca/orgs","repos_url":"https://api.github.com/users/bcoca/repos","events_url":"https://api.github.com/users/bcoca/events{/privacy}","received_events_url":"https://api.github.com/users/bcoca/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/ansible/ansible/milestones/7","html_url":"https://github.com/ansible/ansible/milestones/stable-1.9","labels_url":"https://api.github.com/repos/ansible/ansible/milestones/7/labels","id":1326964,"number":7,"title":"stable-1.9","description":"","creator":{"login":"jimi-c","id":26403,"avatar_url":"https://avatars.githubusercontent.com/u/26403?v=3","gravatar_id":"","url":"https://api.github.com/users/jimi-c","html_url":"https://github.com/jimi-c","followers_url":"https://api.github.com/users/jimi-c/followers","following_url":"https://api.github.com/users/jimi-c/following{/other_user}","gists_url":"https://api.github.com/users/jimi-c/gists{/gist_id}","starred_url":"https://api.github.com/users/jimi-c/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jimi-c/subscriptions","organizations_url":"https://api.github.com/users/jimi-c/orgs","repos_url":"https://api.github.com/users/jimi-c/repos","events_url":"https://api.github.com/users/jimi-c/events{/privacy}","received_events_url":"https://api.github.com/users/jimi-c/received_events","type":"User","site_admin":false},"open_issues":51,"closed_issues":11,"state":"open","created_at":"2015-09-28T14:27:40Z","updated_at":"2016-02-04T16:52:44Z","due_on":null,"closed_at":null},"comments":11,"created_at":"2015-09-30T18:44:27Z","updated_at":"2016-02-10T10:46:28Z","closed_at":null,"body":"*Playbook.yml*\r\n```YAML\r\n---\r\n- name: Bug Report Example\r\n  hosts: testnode.testdomain\r\n  tasks:\r\n    - name: Create lib directory\r\n      file: path=\"lib/\" state=directory\r\n      #local_action: file path=\"lib/\" state=directory\r\n      become: no\r\n      delegate_to: localhost\r\n    - name: Can't do this...\r\n      #local_action: template src=text.j2 dest=lib/file.txt\r\n      template: src=text.j2 dest=lib/file.txt\r\n      delegate_to: localhost\r\n      become: no\r\n```\r\n\r\n\r\n*inventory.ini*\r\n```ini\r\nlocalhost   ansible_connection=local ansible_become=no\r\n\r\ntestnode.testdomain ansible_become=yes\r\n\r\n```\r\n\r\n\r\n*text.j2*\r\n```\r\n# {{ ansible_managed }}\r\nHello World!\r\n```\r\n\r\n*Results*\r\n```\r\nPLAY [Bug Report Example] *****************************************************\r\n\r\nGATHERING FACTS ***************************************************************\r\nok: [testnode.testdomain]\r\n\r\nTASK: [Create lib directory] **************************************************\r\nfailed: [testnode.testdomain -> localhost] => {\"failed\": true, \"parsed\": false}\r\n[sudo via ansible, key=frbjmfdvrioeeqvxbfxiqszlclvpqwjt] password:\r\n\r\n\r\nFATAL: all hosts have already failed -- aborting\r\n```\r\n\r\nI can swap out the delegate_to with the local_action and get the same results.\r\nIf I remove the ansible_become definition from the originating node it will succeed.\r\n\r\nRelated Issue:\r\nhttps://github.com/ansible/ansible/issues/10906\r\n"},"comment":{"url":"https://api.github.com/repos/ansible/ansible/issues/comments/182309803","html_url":"https://github.com/ansible/ansible/issues/12577#issuecomment-182309803","issue_url":"https://api.github.com/repos/ansible/ansible/issues/12577","id":182309803,"user":{"login":"diefans","id":513316,"avatar_url":"https://avatars.githubusercontent.com/u/513316?v=3","gravatar_id":"","url":"https://api.github.com/users/diefans","html_url":"https://github.com/diefans","followers_url":"https://api.github.com/users/diefans/followers","following_url":"https://api.github.com/users/diefans/following{/other_user}","gists_url":"https://api.github.com/users/diefans/gists{/gist_id}","starred_url":"https://api.github.com/users/diefans/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/diefans/subscriptions","organizations_url":"https://api.github.com/users/diefans/orgs","repos_url":"https://api.github.com/users/diefans/repos","events_url":"https://api.github.com/users/diefans/events{/privacy}","received_events_url":"https://api.github.com/users/diefans/received_events","type":"User","site_admin":false},"created_at":"2016-02-10T10:46:28Z","updated_at":"2016-02-10T10:46:28Z","body":"I have a similar problem with ansible==2.0.0.2.\r\n\r\nI want to make some local actions without becoming root within a block:\r\n```\r\n- become: no\r\n  delegate_to: localhost\r\n  block:\r\n    - command: hostname\r\n```\r\n...which ends up in:\r\n```fatal: [test -> localhost]: FAILED! => {\"changed\": false, \"failed\": true, \"invocation\": {\"module_name\": \"command\"}, \"module_stderr\": \"sudo: a password is required\\n\", \"module_stdout\": \"\", \"msg\": \"MODULE FAILURE\", \"parsed\": false}```\r\n\r\n\r\nOne way to fix this is by setting the fact of ```ansible_become=no```and after the block reset this value, but the whole thing is quite expressive:\r\n```\r\n- delegate_to: localhost\r\n  block:\r\n    - set_fact:\r\n        old_ansible_become: \"{{ ansible_become }}\"\r\n\r\n    - set_fact:\r\n        ansible_become: no\r\n\r\n    - command: hostname\r\n\r\n  always:\r\n    - set_fact:\r\n        ansible_become: \"{{ old_ansible_become }}\"\r\n```\r\n\r\nthe other way would be to set the host var for localhost ```ansible_become=no```, but this seems wrong."}}