<h5 dir="auto">ISSUE TYPE</h5>
<p dir="auto">Bug Report</p>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">add_host module</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<p dir="auto">1.9.0.1</p>
<h5 dir="auto">CONFIGURATION</h5>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">Trying to use the add_host module to add fresh servers to a group for tasks later in the playbook I keep getting this error. It will fail the first run but during the second run will work fine. I've included the two previous tasks to show how the with_items works.</p>
<p dir="auto">My tasks:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- name: set hostnames
  hostname: &gt;
    name=&quot;{{ item.tags.Name }}&quot;
  sudo: yes
  delegate_to: &quot;{{ item.private_ip }}&quot;
  with_items: created.tagged_instances

- debug: var=item
  with_items: created.tagged_instances

- name: add hosts to fresh group
  add_host:
    hostname=&quot;{{ item.private_ip }}&quot;
    group=fresh
  with_items: created.tagged_instances"><pre class="notranslate"><code class="notranslate">- name: set hostnames
  hostname: &gt;
    name="{{ item.tags.Name }}"
  sudo: yes
  delegate_to: "{{ item.private_ip }}"
  with_items: created.tagged_instances

- debug: var=item
  with_items: created.tagged_instances

- name: add hosts to fresh group
  add_host:
    hostname="{{ item.private_ip }}"
    group=fresh
  with_items: created.tagged_instances
</code></pre></div>
<p dir="auto">The errors.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TASK: [cep_aws | set hostnames] ***********************************************
&lt;172.20.16.148&gt; REMOTE_MODULE hostname name=&quot;awsqa-cep-primary00&quot;

changed: [localhost -&gt; 172.20.16.148] =&gt; (item={'ramdisk': None, 'kernel': 'aki-919dcaf8', 'root_device_type': 'ebs', 'private_dns_name': 'ip-172-20-16-148.ec2.internal', 'tags': {'ansible': 'awsqa_cep_primary', 'group': 'ancillary', 'Name': 'awsqa-cep-primary00', 'env': 'awsqa', 'app': 'cep', 'class': 'private'}, 'key_name': 'aws', 'public_ip': None, 'image_id': 'ami-cda70ca6', 'tenancy': 'default', 'private_ip': '172.20.16.148', 'groups': {'sg-642d9a03': 'sg_to_bind', 'sg-58c64a3f': 'sg_ec2_qa_cep', 'sg-76cf6c11': 'sg_from_nagios', 'sg-a34d95c4': 'sg_from_warp'}, 'public_dns_name': u'', 'state_code': 16, 'id': 'i-b7960465', 'placement': 'us-east-1b', 'ami_launch_index': '0', 'dns_name': u'', 'region': 'us-east-1', 'ebs_optimized': False, 'launch_time': '2015-08-13T23:28:38.000Z', 'instance_type': 'm3.large', 'state': 'running', 'root_device_name': '/dev/sda', 'hypervisor': 'xen', 'virtualization_type': 'paravirtual', 'architecture': 'x86_64'}) =&gt; {&quot;changed&quot;: true, &quot;item&quot;: {&quot;ami_launch_index&quot;: &quot;0&quot;, &quot;architecture&quot;: &quot;x86_64&quot;, &quot;dns_name&quot;: &quot;&quot;, &quot;ebs_optimized&quot;: false, &quot;groups&quot;: {&quot;sg-58c64a3f&quot;: &quot;sg_ec2_qa_cep&quot;, &quot;sg-642d9a03&quot;: &quot;sg_to_bind&quot;, &quot;sg-76cf6c11&quot;: &quot;sg_from_nagios&quot;, &quot;sg-a34d95c4&quot;: &quot;sg_from_warp&quot;}, &quot;hypervisor&quot;: &quot;xen&quot;, &quot;id&quot;: &quot;i-b7960465&quot;, &quot;image_id&quot;: &quot;ami-cda70ca6&quot;, &quot;instance_type&quot;: &quot;m3.large&quot;, &quot;kernel&quot;: &quot;aki-919dcaf8&quot;, &quot;key_name&quot;: &quot;aws&quot;, &quot;launch_time&quot;: &quot;2015-08-13T23:28:38.000Z&quot;, &quot;placement&quot;: &quot;us-east-1b&quot;, &quot;private_dns_name&quot;: &quot;ip-172-20-16-148.ec2.internal&quot;, &quot;private_ip&quot;: &quot;172.20.16.148&quot;, &quot;public_dns_name&quot;: &quot;&quot;, &quot;public_ip&quot;: null, &quot;ramdisk&quot;: null, &quot;region&quot;: &quot;us-east-1&quot;, &quot;root_device_name&quot;: &quot;/dev/sda&quot;, &quot;root_device_type&quot;: &quot;ebs&quot;, &quot;state&quot;: &quot;running&quot;, &quot;state_code&quot;: 16, &quot;tags&quot;: {&quot;Name&quot;: &quot;awsqa-cep-primary00&quot;, &quot;ansible&quot;: &quot;awsqa_cep_primary&quot;, &quot;app&quot;: &quot;cep&quot;, &quot;class&quot;: &quot;private&quot;, &quot;env&quot;: &quot;awsqa&quot;, &quot;group&quot;: &quot;ancillary&quot;}, &quot;tenancy&quot;: &quot;default&quot;, &quot;virtualization_type&quot;: &quot;paravirtual&quot;}, &quot;name&quot;: &quot;awsqa-cep-primary00&quot;}

TASK: [cep_aws | debug var=item] **********************************************

ok: [localhost] =&gt; (item={'ramdisk': None, 'kernel': 'aki-919dcaf8', 'root_device_type': 'ebs', 'private_dns_name': 'ip-172-20-16-148.ec2.internal', 'tags': {'ansible': 'awsqa_cep_primary', 'group': 'ancillary', 'Name': 'awsqa-cep-primary00', 'env': 'awsqa', 'app': 'cep', 'class': 'private'}, 'key_name': 'aws', 'public_ip': None, 'image_id': 'ami-cda70ca6', 'tenancy': 'default', 'private_ip': '172.20.16.148', 'groups': {'sg-642d9a03': 'sg_to_bind', 'sg-58c64a3f': 'sg_ec2_qa_cep', 'sg-76cf6c11': 'sg_from_nagios', 'sg-a34d95c4': 'sg_from_warp'}, 'public_dns_name': u'', 'state_code': 16, 'id': 'i-b7960465', 'placement': 'us-east-1b', 'ami_launch_index': '0', 'dns_name': u'', 'region': 'us-east-1', 'ebs_optimized': False, 'launch_time': '2015-08-13T23:28:38.000Z', 'instance_type': 'm3.large', 'state': 'running', 'root_device_name': '/dev/sda', 'hypervisor': 'xen', 'virtualization_type': 'paravirtual', 'architecture': 'x86_64'}) =&gt; {
    &quot;item&quot;: {
        &quot;ami_launch_index&quot;: &quot;0&quot;,
        &quot;architecture&quot;: &quot;x86_64&quot;,
        &quot;dns_name&quot;: &quot;&quot;,
        &quot;ebs_optimized&quot;: false,
        &quot;groups&quot;: {
            &quot;sg-58c64a3f&quot;: &quot;sg_ec2_qa_cep&quot;,
            &quot;sg-642d9a03&quot;: &quot;sg_to_bind&quot;,
            &quot;sg-76cf6c11&quot;: &quot;sg_from_nagios&quot;,
            &quot;sg-a34d95c4&quot;: &quot;sg_from_warp&quot;
        },
        &quot;hypervisor&quot;: &quot;xen&quot;,
        &quot;id&quot;: &quot;i-b7960465&quot;,
        &quot;image_id&quot;: &quot;ami-cda70ca6&quot;,
        &quot;instance_type&quot;: &quot;m3.large&quot;,
        &quot;kernel&quot;: &quot;aki-919dcaf8&quot;,
        &quot;key_name&quot;: &quot;aws&quot;,
        &quot;launch_time&quot;: &quot;2015-08-13T23:28:38.000Z&quot;,
        &quot;placement&quot;: &quot;us-east-1b&quot;,
        &quot;private_dns_name&quot;: &quot;ip-172-20-16-148.ec2.internal&quot;,
        &quot;private_ip&quot;: &quot;172.20.16.148&quot;,
        &quot;public_dns_name&quot;: &quot;&quot;,
        &quot;public_ip&quot;: null,
        &quot;ramdisk&quot;: null,
        &quot;region&quot;: &quot;us-east-1&quot;,
        &quot;root_device_name&quot;: &quot;/dev/sda&quot;,
        &quot;root_device_type&quot;: &quot;ebs&quot;,
        &quot;state&quot;: &quot;running&quot;,
        &quot;state_code&quot;: 16,
        &quot;tags&quot;: {
            &quot;Name&quot;: &quot;awsqa-cep-primary00&quot;,
            &quot;ansible&quot;: &quot;awsqa_cep_primary&quot;,
            &quot;app&quot;: &quot;cep&quot;,
            &quot;class&quot;: &quot;private&quot;,
            &quot;env&quot;: &quot;awsqa&quot;,
            &quot;group&quot;: &quot;ancillary&quot;
        },
        &quot;tenancy&quot;: &quot;default&quot;,
        &quot;virtualization_type&quot;: &quot;paravirtual&quot;
    },
    &quot;var&quot;: {
        &quot;item&quot;: {
            &quot;ami_launch_index&quot;: &quot;0&quot;,
            &quot;architecture&quot;: &quot;x86_64&quot;,
            &quot;dns_name&quot;: &quot;&quot;,
            &quot;ebs_optimized&quot;: false,
            &quot;groups&quot;: {
                &quot;sg-58c64a3f&quot;: &quot;sg_ec2_qa_cep&quot;,
                &quot;sg-642d9a03&quot;: &quot;sg_to_bind&quot;,
                &quot;sg-76cf6c11&quot;: &quot;sg_from_nagios&quot;,
                &quot;sg-a34d95c4&quot;: &quot;sg_from_warp&quot;
            },
            &quot;hypervisor&quot;: &quot;xen&quot;,
            &quot;id&quot;: &quot;i-b7960465&quot;,
            &quot;image_id&quot;: &quot;ami-cda70ca6&quot;,
            &quot;instance_type&quot;: &quot;m3.large&quot;,
            &quot;kernel&quot;: &quot;aki-919dcaf8&quot;,
            &quot;key_name&quot;: &quot;aws&quot;,
            &quot;launch_time&quot;: &quot;2015-08-13T23:28:38.000Z&quot;,
            &quot;placement&quot;: &quot;us-east-1b&quot;,
            &quot;private_dns_name&quot;: &quot;ip-172-20-16-148.ec2.internal&quot;,
            &quot;private_ip&quot;: &quot;172.20.16.148&quot;,
            &quot;public_dns_name&quot;: &quot;&quot;,
            &quot;public_ip&quot;: null,
            &quot;ramdisk&quot;: null,
            &quot;region&quot;: &quot;us-east-1&quot;,
            &quot;root_device_name&quot;: &quot;/dev/sda&quot;,
            &quot;root_device_type&quot;: &quot;ebs&quot;,
            &quot;state&quot;: &quot;running&quot;,
            &quot;state_code&quot;: 16,
            &quot;tags&quot;: {
                &quot;Name&quot;: &quot;awsqa-cep-primary00&quot;,
                &quot;ansible&quot;: &quot;awsqa_cep_primary&quot;,
                &quot;app&quot;: &quot;cep&quot;,
                &quot;class&quot;: &quot;private&quot;,
                &quot;env&quot;: &quot;awsqa&quot;,
                &quot;group&quot;: &quot;ancillary&quot;
            },
            &quot;tenancy&quot;: &quot;default&quot;,
            &quot;virtualization_type&quot;: &quot;paravirtual&quot;
        }
    }
}

TASK: [cep_aws | add hosts to fresh group] ************************************
creating host via 'add_host': hostname=172.20.16.148
fatal: [localhost] =&gt; Traceback (most recent call last):
  File &quot;/opt/wp/virtualenv/hegemon/lib/python2.7/site-packages/ansible/runner/__init__.py&quot;, line 582, in _executor
    exec_rc = self._executor_internal(host, new_stdin)
  File &quot;/opt/wp/virtualenv/hegemon/lib/python2.7/site-packages/ansible/runner/__init__.py&quot;, line 811, in _executor_internal
    complex_args=complex_args
  File &quot;/opt/wp/virtualenv/hegemon/lib/python2.7/site-packages/ansible/runner/__init__.py&quot;, line 1028, in _executor_internal_inner
    result = handler.run(conn, tmp, module_name, module_args, inject, complex_args)
  File &quot;/opt/wp/virtualenv/hegemon/lib/python2.7/site-packages/ansible/runner/action_plugins/add_host.py&quot;, line 82, in run
    grp.add_host(new_host)
  File &quot;/opt/wp/virtualenv/hegemon/lib/python2.7/site-packages/ansible/inventory/group.py&quot;, line 67, in add_host
    host.add_group(self)
AttributeError: 'NoneType' object has no attribute 'add_group'


FATAL: all hosts have already failed -- aborting"><pre class="notranslate"><code class="notranslate">TASK: [cep_aws | set hostnames] ***********************************************
&lt;172.20.16.148&gt; REMOTE_MODULE hostname name="awsqa-cep-primary00"

changed: [localhost -&gt; 172.20.16.148] =&gt; (item={'ramdisk': None, 'kernel': 'aki-919dcaf8', 'root_device_type': 'ebs', 'private_dns_name': 'ip-172-20-16-148.ec2.internal', 'tags': {'ansible': 'awsqa_cep_primary', 'group': 'ancillary', 'Name': 'awsqa-cep-primary00', 'env': 'awsqa', 'app': 'cep', 'class': 'private'}, 'key_name': 'aws', 'public_ip': None, 'image_id': 'ami-cda70ca6', 'tenancy': 'default', 'private_ip': '172.20.16.148', 'groups': {'sg-642d9a03': 'sg_to_bind', 'sg-58c64a3f': 'sg_ec2_qa_cep', 'sg-76cf6c11': 'sg_from_nagios', 'sg-a34d95c4': 'sg_from_warp'}, 'public_dns_name': u'', 'state_code': 16, 'id': 'i-b7960465', 'placement': 'us-east-1b', 'ami_launch_index': '0', 'dns_name': u'', 'region': 'us-east-1', 'ebs_optimized': False, 'launch_time': '2015-08-13T23:28:38.000Z', 'instance_type': 'm3.large', 'state': 'running', 'root_device_name': '/dev/sda', 'hypervisor': 'xen', 'virtualization_type': 'paravirtual', 'architecture': 'x86_64'}) =&gt; {"changed": true, "item": {"ami_launch_index": "0", "architecture": "x86_64", "dns_name": "", "ebs_optimized": false, "groups": {"sg-58c64a3f": "sg_ec2_qa_cep", "sg-642d9a03": "sg_to_bind", "sg-76cf6c11": "sg_from_nagios", "sg-a34d95c4": "sg_from_warp"}, "hypervisor": "xen", "id": "i-b7960465", "image_id": "ami-cda70ca6", "instance_type": "m3.large", "kernel": "aki-919dcaf8", "key_name": "aws", "launch_time": "2015-08-13T23:28:38.000Z", "placement": "us-east-1b", "private_dns_name": "ip-172-20-16-148.ec2.internal", "private_ip": "172.20.16.148", "public_dns_name": "", "public_ip": null, "ramdisk": null, "region": "us-east-1", "root_device_name": "/dev/sda", "root_device_type": "ebs", "state": "running", "state_code": 16, "tags": {"Name": "awsqa-cep-primary00", "ansible": "awsqa_cep_primary", "app": "cep", "class": "private", "env": "awsqa", "group": "ancillary"}, "tenancy": "default", "virtualization_type": "paravirtual"}, "name": "awsqa-cep-primary00"}

TASK: [cep_aws | debug var=item] **********************************************

ok: [localhost] =&gt; (item={'ramdisk': None, 'kernel': 'aki-919dcaf8', 'root_device_type': 'ebs', 'private_dns_name': 'ip-172-20-16-148.ec2.internal', 'tags': {'ansible': 'awsqa_cep_primary', 'group': 'ancillary', 'Name': 'awsqa-cep-primary00', 'env': 'awsqa', 'app': 'cep', 'class': 'private'}, 'key_name': 'aws', 'public_ip': None, 'image_id': 'ami-cda70ca6', 'tenancy': 'default', 'private_ip': '172.20.16.148', 'groups': {'sg-642d9a03': 'sg_to_bind', 'sg-58c64a3f': 'sg_ec2_qa_cep', 'sg-76cf6c11': 'sg_from_nagios', 'sg-a34d95c4': 'sg_from_warp'}, 'public_dns_name': u'', 'state_code': 16, 'id': 'i-b7960465', 'placement': 'us-east-1b', 'ami_launch_index': '0', 'dns_name': u'', 'region': 'us-east-1', 'ebs_optimized': False, 'launch_time': '2015-08-13T23:28:38.000Z', 'instance_type': 'm3.large', 'state': 'running', 'root_device_name': '/dev/sda', 'hypervisor': 'xen', 'virtualization_type': 'paravirtual', 'architecture': 'x86_64'}) =&gt; {
    "item": {
        "ami_launch_index": "0",
        "architecture": "x86_64",
        "dns_name": "",
        "ebs_optimized": false,
        "groups": {
            "sg-58c64a3f": "sg_ec2_qa_cep",
            "sg-642d9a03": "sg_to_bind",
            "sg-76cf6c11": "sg_from_nagios",
            "sg-a34d95c4": "sg_from_warp"
        },
        "hypervisor": "xen",
        "id": "i-b7960465",
        "image_id": "ami-cda70ca6",
        "instance_type": "m3.large",
        "kernel": "aki-919dcaf8",
        "key_name": "aws",
        "launch_time": "2015-08-13T23:28:38.000Z",
        "placement": "us-east-1b",
        "private_dns_name": "ip-172-20-16-148.ec2.internal",
        "private_ip": "172.20.16.148",
        "public_dns_name": "",
        "public_ip": null,
        "ramdisk": null,
        "region": "us-east-1",
        "root_device_name": "/dev/sda",
        "root_device_type": "ebs",
        "state": "running",
        "state_code": 16,
        "tags": {
            "Name": "awsqa-cep-primary00",
            "ansible": "awsqa_cep_primary",
            "app": "cep",
            "class": "private",
            "env": "awsqa",
            "group": "ancillary"
        },
        "tenancy": "default",
        "virtualization_type": "paravirtual"
    },
    "var": {
        "item": {
            "ami_launch_index": "0",
            "architecture": "x86_64",
            "dns_name": "",
            "ebs_optimized": false,
            "groups": {
                "sg-58c64a3f": "sg_ec2_qa_cep",
                "sg-642d9a03": "sg_to_bind",
                "sg-76cf6c11": "sg_from_nagios",
                "sg-a34d95c4": "sg_from_warp"
            },
            "hypervisor": "xen",
            "id": "i-b7960465",
            "image_id": "ami-cda70ca6",
            "instance_type": "m3.large",
            "kernel": "aki-919dcaf8",
            "key_name": "aws",
            "launch_time": "2015-08-13T23:28:38.000Z",
            "placement": "us-east-1b",
            "private_dns_name": "ip-172-20-16-148.ec2.internal",
            "private_ip": "172.20.16.148",
            "public_dns_name": "",
            "public_ip": null,
            "ramdisk": null,
            "region": "us-east-1",
            "root_device_name": "/dev/sda",
            "root_device_type": "ebs",
            "state": "running",
            "state_code": 16,
            "tags": {
                "Name": "awsqa-cep-primary00",
                "ansible": "awsqa_cep_primary",
                "app": "cep",
                "class": "private",
                "env": "awsqa",
                "group": "ancillary"
            },
            "tenancy": "default",
            "virtualization_type": "paravirtual"
        }
    }
}

TASK: [cep_aws | add hosts to fresh group] ************************************
creating host via 'add_host': hostname=172.20.16.148
fatal: [localhost] =&gt; Traceback (most recent call last):
  File "/opt/wp/virtualenv/hegemon/lib/python2.7/site-packages/ansible/runner/__init__.py", line 582, in _executor
    exec_rc = self._executor_internal(host, new_stdin)
  File "/opt/wp/virtualenv/hegemon/lib/python2.7/site-packages/ansible/runner/__init__.py", line 811, in _executor_internal
    complex_args=complex_args
  File "/opt/wp/virtualenv/hegemon/lib/python2.7/site-packages/ansible/runner/__init__.py", line 1028, in _executor_internal_inner
    result = handler.run(conn, tmp, module_name, module_args, inject, complex_args)
  File "/opt/wp/virtualenv/hegemon/lib/python2.7/site-packages/ansible/runner/action_plugins/add_host.py", line 82, in run
    grp.add_host(new_host)
  File "/opt/wp/virtualenv/hegemon/lib/python2.7/site-packages/ansible/inventory/group.py", line 67, in add_host
    host.add_group(self)
AttributeError: 'NoneType' object has no attribute 'add_group'


FATAL: all hosts have already failed -- aborting
</code></pre></div>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<h5 dir="auto">EXPECTED RESULTS</h5>
<h5 dir="auto">ACTUAL RESULTS</h5>
<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">delegate_to</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.4.2.0
  config file = /Users/tagir/.config/ansible/ansible.cfg
  configured module search path = [u'/Users/tagir/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/Cellar/ansible/2.4.2.0_1/libexec/lib/python2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.14 (default, Sep 25 2017, 09:53:22) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)]"><pre class="notranslate"><code class="notranslate">ansible 2.4.2.0
  config file = /Users/tagir/.config/ansible/ansible.cfg
  configured module search path = [u'/Users/tagir/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/Cellar/ansible/2.4.2.0_1/libexec/lib/python2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.14 (default, Sep 25 2017, 09:53:22) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)]
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=" ANSIBLE_PIPELINING(/Users/tagir/.config/ansible/ansible.cfg) = True
 CACHE_PLUGIN(/Users/tagir/.config/ansible/ansible.cfg) = jsonfile
 CACHE_PLUGIN_CONNECTION(/Users/tagir/.config/ansible/ansible.cfg) = .
 CACHE_PLUGIN_TIMEOUT(/Users/tagir/.config/ansible/ansible.cfg) = 60
 DEFAULT_BECOME_METHOD(/Users/tagir/.config/ansible/ansible.cfg) = su
 DEFAULT_GATHERING(/Users/tagir/.config/ansible/ansible.cfg) = smart
 DEFAULT_JINJA2_EXTENSIONS(/Users/tagir/.config/ansible/ansible.cfg) = jinja2.ext.do
 DEFAULT_MODULE_NAME(/Users/tagir/.config/ansible/ansible.cfg) = shell
 DEFAULT_ROLES_PATH(/Users/tagir/.config/ansible/ansible.cfg) = [u'/Users/tagir/git/ansible/r oles']
 DEFAULT_STDOUT_CALLBACK(/Users/tagir/.config/ansible/ansible.cfg) = debug
 RETRY_FILES_ENABLED(/Users/tagir/.config/ansible/ansible.cfg) = False"><pre class="notranslate"><code class="notranslate"> ANSIBLE_PIPELINING(/Users/tagir/.config/ansible/ansible.cfg) = True
 CACHE_PLUGIN(/Users/tagir/.config/ansible/ansible.cfg) = jsonfile
 CACHE_PLUGIN_CONNECTION(/Users/tagir/.config/ansible/ansible.cfg) = .
 CACHE_PLUGIN_TIMEOUT(/Users/tagir/.config/ansible/ansible.cfg) = 60
 DEFAULT_BECOME_METHOD(/Users/tagir/.config/ansible/ansible.cfg) = su
 DEFAULT_GATHERING(/Users/tagir/.config/ansible/ansible.cfg) = smart
 DEFAULT_JINJA2_EXTENSIONS(/Users/tagir/.config/ansible/ansible.cfg) = jinja2.ext.do
 DEFAULT_MODULE_NAME(/Users/tagir/.config/ansible/ansible.cfg) = shell
 DEFAULT_ROLES_PATH(/Users/tagir/.config/ansible/ansible.cfg) = [u'/Users/tagir/git/ansible/r oles']
 DEFAULT_STDOUT_CALLBACK(/Users/tagir/.config/ansible/ansible.cfg) = debug
 RETRY_FILES_ENABLED(/Users/tagir/.config/ansible/ansible.cfg) = False
</code></pre></div>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">N/A</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">In my environment <code class="notranslate">ansible_become_pass</code> is defined on a per-host basis. This does not play well with the delegated tasks, because instead of using the password of the host the task is delegated to, the password of the delegating host is used.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<p dir="auto">Sample inventory file:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="---
all:
  hosts:
    ns1:
      ansible_become_pass: ns1
    ns2:
      ansible_become_pass: ns2
    ns3:
      ansible_become_pass: ns3"><pre class="notranslate">---
<span class="pl-ent">all</span>:
  <span class="pl-ent">hosts</span>:
    <span class="pl-ent">ns1</span>:
      <span class="pl-ent">ansible_become_pass</span>: <span class="pl-s">ns1</span>
    <span class="pl-ent">ns2</span>:
      <span class="pl-ent">ansible_become_pass</span>: <span class="pl-s">ns2</span>
    <span class="pl-ent">ns3</span>:
      <span class="pl-ent">ansible_become_pass</span>: <span class="pl-s">ns3</span></pre></div>
<p dir="auto">Sample playbook:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="---
- hosts: all
  tasks:
    - debug: msg=&quot;{{ ansible_become_pass }}&quot;
      delegate_to: ns1"><pre class="notranslate">---
- <span class="pl-ent">hosts</span>: <span class="pl-s">all</span>
  <span class="pl-ent">tasks</span>:
    - <span class="pl-ent">debug</span>: <span class="pl-s">msg="{{ ansible_become_pass }}"</span>
      <span class="pl-ent">delegate_to</span>: <span class="pl-s">ns1</span></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto"><code class="notranslate">ansible_become_pass</code> to be <code class="notranslate">ns1</code> for every run of the delegated task.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<p dir="auto">The value of the <code class="notranslate">ansible_become_pass</code> is taken from the variables of the respective host.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ ansible-playbook -i inventory.yml playbook.yml

PLAY [all] **********************************************************************************

TASK [debug] ********************************************************************************
ok: [ns1 -&gt; None] =&gt; {}

MSG:

ns1

ok: [ns2 -&gt; None] =&gt; {}

MSG:

ns2

ok: [ns3 -&gt; None] =&gt; {}

MSG:

ns3


PLAY RECAP **********************************************************************************
ns1                        : ok=1    changed=0    unreachable=0    failed=0
ns2                        : ok=1    changed=0    unreachable=0    failed=0
ns3                        : ok=1    changed=0    unreachable=0    failed=0"><pre class="notranslate"><code class="notranslate">$ ansible-playbook -i inventory.yml playbook.yml

PLAY [all] **********************************************************************************

TASK [debug] ********************************************************************************
ok: [ns1 -&gt; None] =&gt; {}

MSG:

ns1

ok: [ns2 -&gt; None] =&gt; {}

MSG:

ns2

ok: [ns3 -&gt; None] =&gt; {}

MSG:

ns3


PLAY RECAP **********************************************************************************
ns1                        : ok=1    changed=0    unreachable=0    failed=0
ns2                        : ok=1    changed=0    unreachable=0    failed=0
ns3                        : ok=1    changed=0    unreachable=0    failed=0
</code></pre></div>