Pinging another machine using AWS/ec2 dynamic inventory

347 צפיות
מעבר להודעה הראשונה שלא נקראה

Sven Ehlert

לא נקראה,
11 בדצמ׳ 2014, 5:33:3011.12.2014
עד ansible...@googlegroups.com
Hi all,

I have a rather simple usecase for which I don't seem to find an answer.

How can I ping a AWS/ec2 instance from another instance in a different play? I'm using the dynamic inventory.

The scenario is like this:

I create two ec2 instance in a play like this:

ec2:  
   
group: "{{ security_group }}"
    instance_type
: "{{ instance_type }}"
    image
: "{{ image }}"
    region
: "{{ region }}"
    key_name
: "{{ keypair }}"
    instance_tags
:
       
Name: Destination


ec2
:  
   
group: "{{ security_group }}"
    instance_type
: "{{ instance_type }}"
    image
: "{{ image }}"
    region
: "{{ region }}"
    key_name
: "{{ keypair }}"
    instance_tags
:
       
Name: Source

This works well, the nodes are started and I can see them when running ./ec2.py

Then, in another play  (ping.yml) I want to do this

- name: pinging host
  hosts: tag_Name_Source
  remote_user: ubuntu

  tasks: 
  - shell: ping {{ tag_Name_Destination }}

I run it with 
ansible-playbook -i ec2.py ping.yml
but it gives me "One or more undefined variables: 'tag_Name_Destination' is undefined"

What is the right way to get the IP of the target machine?

I'm running Ansible 1.8.2 on Ubuntu.

Thanks for any hints.
/Sven



   

James Cammarata

לא נקראה,
11 בדצמ׳ 2014, 10:32:1511.12.2014
עד ansible...@googlegroups.com
Hi Sven, this is most likely due to the caching of data by the inventory script. You can set "cache_max_age = 0" in your ec2.ini to disable caching, to see if that helps.

--
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/2e04f49d-d154-471e-89fd-0d626866ae4c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sven Ehlert

לא נקראה,
18 בדצמ׳ 2014, 8:44:1118.12.2014
עד ansible...@googlegroups.com
Hi James,

thanks for the reply, however that didn't work out.
I get the same error ""One or more undefined variables: 'tag_Name_Destination' is undefined"

I can even simplify my playbook to "ping myself"


- name: pinging myself
  hosts
: tag_Name_Source


  tasks
:
 
- shell: ping {{ tag_Name_Source }}



and I still get
PLAY [pinging myself] ***********************************************************


GATHERING FACTS
***************************************************************
ok
: [xx.xx.xx.xx]


TASK
: [shell ping {{ tag_Name_Source }}] **************************************
fatal
: [xx.xx.xx.xx] => One or more undefined variables: 'tag_Name_Source' is undefined



That is, while Ansible understands 'tag_Name_Source' in the 'hosts:' section, it doesn't understand the same variable in the "shell:" section.
Do I need to use a special syntax when using variables with {{ }}?

Sven Ehlert

לא נקראה,
11 בפבר׳ 2015, 6:37:0111.2.2015
עד ansible...@googlegroups.com
I found a solution myself. The following playbook works as expected. This should be added to the ec2 tutorial.


- name: pinging myself
  hosts
: tag_Name_Source


  tasks
:
 
  
- shell: ping {{ groups['tag_Name_Source'][0] }}


השב לכולם
השב למחבר
העבר לנמענים
0 הודעות חדשות