- hosts: localhost
connection: local
gather_facts: False
vars:
instance_name: "somename"
-tasks:
--snipped--
--snipped--
# Connect to the node and gather facts, including the instance-id. These facts
# are added to inventory hostvars for the duration of the playbook's execution
# Typical "provisioning" tasks would go in this playbook.
- hosts: ec2hosts
gather_facts: True
user: admin
sudo: True
tasks:
# fetch instance data from the metadata servers in ec2
- ec2_facts:
# show all known facts for this host
- debug: var=hostvars[inventory_hostname]
# just show the instance-id
- debug: msg="{{ hostvars[inventory_hostname]['ansible_ec2_instance_id'] }}"
- name: set hostname to {{ instance_name }}
hostname:
name: "{{ instance_name }}"
TASK: [set hostname to {{ instance_name }}] ***********************************
fatal: [54.xx.xx.xx] => One or more undefined variables: 'instance_name' is undefined
FATAL: all hosts have already failed -- aborting
PLAY RECAP ********************************************************************On the Mac (Yosemite), this part goes without any incident:
TASK: [set hostname to somename] *************************************************
changed: [54.xx.xx.xx]
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/e4480e53-547b-4f74-a519-879213793633%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.