To wrap this whole thread up with a nice bow for anyone following behind:

There are three problems:
1. You need information from another server to use in the current server 
you're configuring.
2. The other server you need information from is hosted in AWS.
3. The other server you need to access information about has a variable name

The solution to 3 is to specify the variable in the command line using 
extra-vars like so: ansible-playbook -i ./ec2.py --extra-vars "chaos=test" 
aws_playground.yaml

The solution to 2 is to find the hostname you need from the hostvars' 
groups variable. When combined with 3 above, you want something like: - 
debug: 
var=hostvars[groups['tag_Name_'+chaos+'_util'][0]].ansible_all_ipv4_addresses[0]

The solution to 1 is to first collect facts from the other server before 
working on the server you're configuring. Below is a playbook collecting 
all this in one place:

---
# Called like: ansible-playbook -i ./ec2.py --extra-vars "chaos=test" 
aws_playground.yaml
- name: Collect our facts on util
  hosts: "tag_Name_{{ chaos }}_util"
  tasks: [ ]

- name: Set up a web server
  hosts: "tag_Name_{{ chaos }}_web"
  tasks:
   - debug: 
var=hostvars[groups['tag_Name_'+chaos+'_util'][0]].ansible_all_ipv4_addresses[0]


On Monday, June 20, 2016 at 3:04:53 PM UTC-4, Anthony Sheetz wrote:
>
> I need to access information discovered from another server for a template 
> on the server I'm configuring.
>
> We are using AWS, and I'm of course using ec2.py to discover my hosts. I 
> first configure a utility server, and then configure my web servers. I tag 
> the utility server with an appropriate Name, and then in my web server 
> configuration playbook I include a bit to discover facts about the utility 
> server using appropriate tags. How do I then reference the facts about the 
> utility server in the templates for the web server?
>
> If I dump hostvars, I can see the information I want does exist, I just 
> can't convince Google to show me an example to follow.
>
> Here's an example playbook which DOES NOT work, but does illustrate the 
> context:
>
> ---
>>
>> # Called like: ansible-playbook -i ./ec2.py --extra-vars "chaos=test" 
>>> aws_playground.yaml
>>
>> - name: Collect our facts on bc-util
>>
>>   hosts: "tag_Name_{{ chaos }}_bc_util"
>>
>>   tasks:
>>
>>   - debug: var=ansible_all_ipv4_addresses
>>
>>  
>
>> - name: Set up a bc-web server
>>
>>   hosts: "tag_Name_{{ chaos }}_bc_web"
>>
>>   become: yes
>>
>>   become_user: root
>>
>>   remote_user: admin
>>
>>   tasks:
>>
>>   - debug: msg="{{ hostvars }}"
>>
>>

-- 
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/e1476e6e-1d94-410f-9a27-4769d57fefaa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to