Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'ansible_date_time' is undefined

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).

This is what I have:

- 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 

From ami_vars.yml:

ami_version: "{{ ansible_date_time.iso8601 }}" ami_name: ami_test_{{ ami_version }} 

When I run the full playbook, I get this error message:

fatal: [localhost]: FAILED! => {"failed": true, "msg": "ERROR! ERROR! ERROR! 'ansible_date_time' is undefined"} 

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

- 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 }}" 

Result:

TASK [debug] ******************************************************************* ok: [localhost] => {     "msg": "ami version is 2016-02-05T19:32:24Z" }  TASK [debug] ******************************************************************* ok: [localhost] => {     "msg": "ami name is ami_test_2016-02-05T19:32:24Z" } 

Any idea what's going on?

like image 279
Don Julio Avatar asked Feb 05 '16 19:02

Don Julio


1 Answers

Remove this:

  gather_facts: false 

ansible_date_time is part of the facts and you are not gathering it.

like image 200
helloV Avatar answered Sep 28 '22 09:09

helloV