<p dir="auto">From <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/alexmiller422/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/alexmiller422">@alexmiller422</a> on 2016-01-26T10:42:28Z</p>
<h5 dir="auto">ISSUE TYPE</h5>
<p dir="auto">Bug Report</p>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">ec2 module</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<p dir="auto">N/A</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">Starting stopped EC2 instances selected by tags fails when wait is set to 'yes'</p>
<p dir="auto">Task:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="  ec2:
    region: &quot;{{region}}&quot;
    instance_tags: {CustomerID: &quot;{{customer_id}}&quot;, Owner: &quot;{{owner}}&quot;, Environment: &quot;{{environment_tag}}&quot;, Server: all-in-one}
    key_name: &quot;{{key_name}}&quot;
    assign_public_ip: yes
    state: running
    wait: yes "><pre class="notranslate">  <span class="pl-ent">ec2</span>:
    <span class="pl-ent">region</span>: <span class="pl-s"><span class="pl-pds">"</span>{{region}}<span class="pl-pds">"</span></span>
    <span class="pl-ent">instance_tags</span>: <span class="pl-s">{CustomerID: "{{customer_id}}", Owner: "{{owner}}", Environment: "{{environment_tag}}", Server: all-in-one}</span>
    <span class="pl-ent">key_name</span>: <span class="pl-s"><span class="pl-pds">"</span>{{key_name}}<span class="pl-pds">"</span></span>
    <span class="pl-ent">assign_public_ip</span>: <span class="pl-s">yes</span>
    <span class="pl-ent">state</span>: <span class="pl-s">running</span>
    <span class="pl-ent">wait</span>: <span class="pl-s">yes </span></pre></div>
<p dir="auto">Output:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ESTABLISH LOCAL CONNECTION FOR USER: amiller
127.0.0.1 EXEC ( umask 22 &amp;&amp; mkdir -p &quot;$( echo $HOME/.ansible/tmp/ansible-tmp-1453803313.05-62519916455476 )&quot; &amp;&amp; echo &quot;$( echo $HOME/.ansible/tmp/ansible-tmp-1453803313.05-62519916455476 )&quot; )
127.0.0.1 PUT /var/folders/6x/3h7k4ch51xsbv40h57h5csd40000gp/T/tmpZy3jwL TO /Users/amiller/.ansible/tmp/ansible-tmp-1453803313.05-62519916455476/ec2
127.0.0.1 EXEC LANG=en_GB.UTF-8 LC_ALL=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8 /usr/bin/python /Users/amiller/.ansible/tmp/ansible-tmp-1453803313.05-62519916455476/ec2; rm -rf &quot;/Users/amiller/.ansible/tmp/ansible-tmp-1453803313.05-62519916455476/&quot; &gt; /dev/null 2&gt;&amp;1
An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
  File &quot;/Users/amiller/.ansible/tmp/ansible-tmp-1453803313.05-62519916455476/ec2&quot;, line 3582, in &lt;module&gt;
    main()
  File &quot;/Users/amiller/.ansible/tmp/ansible-tmp-1453803313.05-62519916455476/ec2&quot;, line 1405, in main
    (changed, instance_dict_array, new_instance_ids) = startstop_instances(module, ec2, instance_ids, state, instance_tags)
  File &quot;/Users/amiller/.ansible/tmp/ansible-tmp-1453803313.05-62519916455476/ec2&quot;, line 1308, in startstop_instances
    if len(matched_instances) &lt; len(instance_ids):
TypeError: object of type 'NoneType' has no len()

fatal: [localhost]: FAILED! =&gt; {&quot;changed&quot;: false, &quot;failed&quot;: true, &quot;invocation&quot;: {&quot;module_name&quot;: &quot;ec2&quot;}, &quot;parsed&quot;: false}"><pre class="notranslate"><code class="notranslate">ESTABLISH LOCAL CONNECTION FOR USER: amiller
127.0.0.1 EXEC ( umask 22 &amp;&amp; mkdir -p "$( echo $HOME/.ansible/tmp/ansible-tmp-1453803313.05-62519916455476 )" &amp;&amp; echo "$( echo $HOME/.ansible/tmp/ansible-tmp-1453803313.05-62519916455476 )" )
127.0.0.1 PUT /var/folders/6x/3h7k4ch51xsbv40h57h5csd40000gp/T/tmpZy3jwL TO /Users/amiller/.ansible/tmp/ansible-tmp-1453803313.05-62519916455476/ec2
127.0.0.1 EXEC LANG=en_GB.UTF-8 LC_ALL=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8 /usr/bin/python /Users/amiller/.ansible/tmp/ansible-tmp-1453803313.05-62519916455476/ec2; rm -rf "/Users/amiller/.ansible/tmp/ansible-tmp-1453803313.05-62519916455476/" &gt; /dev/null 2&gt;&amp;1
An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
  File "/Users/amiller/.ansible/tmp/ansible-tmp-1453803313.05-62519916455476/ec2", line 3582, in &lt;module&gt;
    main()
  File "/Users/amiller/.ansible/tmp/ansible-tmp-1453803313.05-62519916455476/ec2", line 1405, in main
    (changed, instance_dict_array, new_instance_ids) = startstop_instances(module, ec2, instance_ids, state, instance_tags)
  File "/Users/amiller/.ansible/tmp/ansible-tmp-1453803313.05-62519916455476/ec2", line 1308, in startstop_instances
    if len(matched_instances) &lt; len(instance_ids):
TypeError: object of type 'NoneType' has no len()

fatal: [localhost]: FAILED! =&gt; {"changed": false, "failed": true, "invocation": {"module_name": "ec2"}, "parsed": false}
</code></pre></div>
<p dir="auto">I believe this is a duplicate of <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="114978022" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible/issues/13030" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible/issues/13030/hovercard" href="https://github.com/ansible/ansible/issues/13030">#13030</a></p>
<p dir="auto">Copied from original issue: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="128786890" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible-modules-core/issues/2886" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible-modules-core/issues/2886/hovercard" href="https://github.com/ansible/ansible-modules-core/issues/2886">ansible/ansible-modules-core#2886</a></p>
<h5 dir="auto">ISSUE TYPE</h5>

<ul dir="auto">
<li><del>B ug Report</del></li>
<li>Feature Idea</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>

<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.3.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.13 (default, Jun 26 2017, 10:20:05) [GCC 7.1.1 20170622 (Red Hat 7.1.1-3)]"><pre class="notranslate"><code class="notranslate">ansible 2.3.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.13 (default, Jun 26 2017, 10:20:05) [GCC 7.1.1 20170622 (Red Hat 7.1.1-3)]
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>

<h5 dir="auto">OS / ENVIRONMENT</h5>

<p dir="auto">N/A</p>
<h5 dir="auto">SUMMARY</h5>

<p dir="auto">When running a playbook that has a yaml anchor in a task and it is used in a subsequent task that overrides some of the original keys, with no verbosity specified, the user gets ugly warnings.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>

<p dir="auto">Among some other tasks, I have these:</p>

<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- &amp;iamuserupdate
  name: create present bucket iam users
  with_subelements:
    - &quot;{{ s3_buckets }}&quot;
    - users
  when:
    - item.0.state|default('present') != 'absent'
  iam:
    &lt;&lt;: *aws_access
    name: &quot;{{ item.1 }}&quot;
    iam_type: user
    state: &quot;{{ item.0.state|default('present') }}&quot;

# Other tasks, not relevant

- &lt;&lt;: *iamuserupdate
  name: delete absent bucket iam users
  when:
    - item.0.state|default('present') == 'absent'"><pre class="notranslate"><span class="pl-s">- &amp;iamuserupdate</span>
  <span class="pl-ent">name</span>: <span class="pl-s">create present bucket iam users</span>
  <span class="pl-ent">with_subelements</span>:
    - <span class="pl-s"><span class="pl-pds">"</span>{{ s3_buckets }}<span class="pl-pds">"</span></span>
    - <span class="pl-s">users</span>
  <span class="pl-ent">when</span>:
    - <span class="pl-s">item.0.state|default('present') != 'absent'</span>
  <span class="pl-ent">iam</span>:
    <span class="pl-ent">&lt;&lt;</span>: <span class="pl-s">*aws_access</span>
    <span class="pl-ent">name</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ item.1 }}<span class="pl-pds">"</span></span>
    <span class="pl-ent">iam_type</span>: <span class="pl-s">user</span>
    <span class="pl-ent">state</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ item.0.state|default('present') }}<span class="pl-pds">"</span></span>

<span class="pl-c"><span class="pl-c">#</span> Other tasks, not relevant</span>

- <span class="pl-ent">&lt;&lt;</span>: <span class="pl-s">*iamuserupdate</span>
  <span class="pl-ent">name</span>: <span class="pl-s">delete absent bucket iam users</span>
  <span class="pl-ent">when</span>:
    - <span class="pl-s">item.0.state|default('present') == 'absent'</span></pre></div>

<h5 dir="auto">EXPECTED RESULTS</h5>

<p dir="auto">I don't want to get those ugly warnings for doing something that I did on purpose and expected it to happen: overriding a task definition on some keys that already existed in the previous task.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>


<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=" [WARNING]: While constructing a mapping from /path/roles/aws-
manager/tasks/setup.yaml, line 147, column 3, found a duplicate dict key (name). Using last defined value only.

 [WARNING]: While constructing a mapping from /path/roles/aws-
manager/tasks/setup.yaml, line 147, column 3, found a duplicate dict key (when). Using last defined value only."><pre class="notranslate"><code class="notranslate"> [WARNING]: While constructing a mapping from /path/roles/aws-
manager/tasks/setup.yaml, line 147, column 3, found a duplicate dict key (name). Using last defined value only.

 [WARNING]: While constructing a mapping from /path/roles/aws-
manager/tasks/setup.yaml, line 147, column 3, found a duplicate dict key (when). Using last defined value only.
</code></pre></div>
<p dir="auto">Those warnings are OK, but only in <code class="notranslate">-v</code> mode at least.</p>