On 20.03.2018 16:41, Ukesh Kumar Vasudevan wrote:
I am having the below ansible script.

While executing the script, I am getting error in the role 'install-packages'.
The error is,

"msg": "The task includes an option with an undefined variable. The error
was: {{ ip }}: 'ip' is undefined.

It is looking for 'ip' variable inside the role 'install-packages',

Please provide your feedback..

---

# Create an EC2 instance

- name: Create EC2 Instance
  hosts: "local"
  connection: "local"
  roles:
    - ec2-provision

- name: set_facts
  hosts: local
  tasks:
    - set_fact:
        ip: "{{ ec2.instances[0].private_ip }}"
    - debug:
        var: ip

- name: Install packages
  hosts: new_vms
  gather_facts: yes
  vars:
    ip_addrs: "{{ ip }}"
  roles:
   - install-packages

You are setting the variable on host local not on host new_vms so the variable ip doesn't exist there. To access the variable you need to use hostvars and specify which host you like the get the ip variable from.

  {{ hostvars['local'].ip }}

--
Kai Stian Olstad

--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/d37f4f6e536583939f187e96371faefc%40olstad.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to