<p dir="auto">From <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/srkiNZ84/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/srkiNZ84">@srkiNZ84</a> on 2016-05-09T22:40:20Z</p>
<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">ec2_asg</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.0.0.2"><pre class="notranslate"><code class="notranslate">ansible 2.0.0.2
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">Running from: Ubuntu Linux<br>
Managing: Ubuntu Linux</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">We (seeming randomly) get cases where we'll do a blue/green deploy using the "ec2_asg" module and have an async task waiting for the module to return a result. The task that waits for the result never gets the async notification and therefore fails despite the deploy succeeding.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<ul dir="auto">
<li>Create a new launch config (our new "blue" deploy)</li>
<li>Run the "ec2_asg" task with the new launch config (with async set and "poll: 0")</li>
<li>Have a task later in the playbook waiting on the result</li>
<li>Confirm that the deploy succeeds in AWS (new instances brought up, old ones terminated)</li>
<li>See that the "async_status" job never gets the notification that the deploy has happened</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- name: Create integration tier launch configuration
  ec2_lc:
    name: &quot;{{ environ }}-int-launch-config-{{ current_time }}&quot;
    [OMITTED FOR BREVITY]
  register: int_launch_configuration

- name: Create Integration Autoscaling group
  ec2_asg:
    name: &quot;{{ environ }}-int-asg&quot;
    launch_config_name: &quot;{{ environ }}-int-launch-config-{{ current_time }}&quot;
    vpc_zone_identifier: &quot;{{ int_subnets }}&quot;
    health_check_type: &quot;ELB&quot;
    health_check_period: 400
    termination_policies: &quot;OldestInstance&quot;
    replace_all_instances: yes
    wait_timeout: 2400
    replace_batch_size: &quot;{{ int_replace_batch_size }}&quot;
  async: 1000
  poll: 0
  register: int_asg_sleeper

  - name: 'int ASG - check on fire and forget task'
    async_status: jid={{ int_asg_sleeper.ansible_job_id }}
    register: int_asg_job_result
    until: int_asg_job_result.finished
    retries: 60
    delay: 15"><pre class="notranslate"><code class="notranslate">- name: Create integration tier launch configuration
  ec2_lc:
    name: "{{ environ }}-int-launch-config-{{ current_time }}"
    [OMITTED FOR BREVITY]
  register: int_launch_configuration

- name: Create Integration Autoscaling group
  ec2_asg:
    name: "{{ environ }}-int-asg"
    launch_config_name: "{{ environ }}-int-launch-config-{{ current_time }}"
    vpc_zone_identifier: "{{ int_subnets }}"
    health_check_type: "ELB"
    health_check_period: 400
    termination_policies: "OldestInstance"
    replace_all_instances: yes
    wait_timeout: 2400
    replace_batch_size: "{{ int_replace_batch_size }}"
  async: 1000
  poll: 0
  register: int_asg_sleeper

  - name: 'int ASG - check on fire and forget task'
    async_status: jid={{ int_asg_sleeper.ansible_job_id }}
    register: int_asg_job_result
    until: int_asg_job_result.finished
    retries: 60
    delay: 15
</code></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">Expected that when the deploy succeeds and the "old" instances are terminated, the Async job gets the message and reports success.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<p dir="auto">It appears that the "file" mechanism which Python/Ansible use for checking on the status of background jobs fails and the file is never populated, despite the job finishing. Therefore the job polling the file times out eventually.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="08:03:34.063 TASK [launch-config : int ASG - check on fire and forget task] *****************
08:03:34.130 fatal: [localhost]: FAILED! =&gt; {&quot;failed&quot;: true, &quot;msg&quot;: &quot;ERROR! The conditional check 'int_asg_job_result.finished' failed. The error was: ERROR! error while evaluating conditional (int_asg_job_result.finished): ERROR! 'dict object' has no attribute 'finished'&quot;}"><pre class="notranslate"><code class="notranslate">08:03:34.063 TASK [launch-config : int ASG - check on fire and forget task] *****************
08:03:34.130 fatal: [localhost]: FAILED! =&gt; {"failed": true, "msg": "ERROR! The conditional check 'int_asg_job_result.finished' failed. The error was: ERROR! error while evaluating conditional (int_asg_job_result.finished): ERROR! 'dict object' has no attribute 'finished'"}
</code></pre></div>
<p dir="auto">Copied from original issue: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="153886135" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible-modules-core/issues/3625" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible-modules-core/issues/3625/hovercard" href="https://github.com/ansible/ansible-modules-core/issues/3625">ansible/ansible-modules-core#3625</a></p>
<p dir="auto">It would be nice to be possible to specify vars in tasks files such as the following:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# playbook.yml
- hosts: localhost
  tasks:
    - include: tasks.yml"><pre class="notranslate"><code class="notranslate"># playbook.yml
- hosts: localhost
  tasks:
    - include: tasks.yml
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# tasks.yml
vars:
- path: /srv/bar

- name: copy file foo
  action: copy src=foo dest=$path/foo

- name: copy file bar
  action: copy src=bar dest=$path/bar"><pre class="notranslate"><code class="notranslate"># tasks.yml
vars:
- path: /srv/bar

- name: copy file foo
  action: copy src=foo dest=$path/foo

- name: copy file bar
  action: copy src=bar dest=$path/bar
</code></pre></div>
<p dir="auto">This allows to bundle common strings inside a tasks file.</p>