'ansible_date_time' is undefined : <p>Trying to register an ec2 instance in AWS with Ansible's ec2_ami module, and using current date/time as version (we'll end up making a lot of AMIs in the future).</p>

<p>This is what I have:</p>

<pre><code>- name: Create new AMI
  hosts: localhost
  connection: local
  gather_facts: false
  vars:
  tasks:
    - include_vars: ami_vars.yml
    - debug: var=ansible_date_time
    - name: Register ec2 instance as AMI
      ec2_ami: aws_access_key={{ ec2_access_key }}
               aws_secret_key={{ ec2_secret_key }}
               instance_id={{ temp_instance.instance_ids[0] }}
               region={{ region }}
               wait=yes
               name={{ ami_name }}
      with_items: temp_instance
      register: new_ami
</code></pre>

<p>From ami_vars.yml:</p>

<pre><code>ami_version: "{{ ansible_date_time.iso8601 }}"
ami_name: ami_test_{{ ami_version }}
</code></pre>

<p>When I run the full playbook, I get this error message:</p>

<pre><code>fatal: [localhost]: FAILED! =&gt; {"failed": true, "msg": "ERROR! ERROR! ERROR! 'ansible_date_time' is undefined"}
</code></pre>

<p>However, when run the debug command separately, from a separate playbook, it works fine:</p>

<pre><code>- name: Test date-time lookup
  hosts: localhost
  connection: local
  tasks:
    - include_vars: ami_vars.yml
    - debug: msg="ami version is {{ ami_version }}"
    - debug: msg="ami name is {{ ami_name }}"
</code></pre>

<p>Result:</p>

<pre><code>TASK [debug] *******************************************************************
ok: [localhost] =&gt; {
    "msg": "ami version is 2016-02-05T19:32:24Z"
}

TASK [debug] *******************************************************************
ok: [localhost] =&gt; {
    "msg": "ami name is ami_test_2016-02-05T19:32:24Z"
}
</code></pre>

<p>Any idea what's going on?</p>
