- name: Create instance(s)
hosts: local
gather_facts: no
connection: local
tags: provisioning
vars:
....
groupname: launched
port: 8080 - name: Add host to groupname
add_host: hostname={{ item.public_ip }} ansible_ssh_private_key_file=PATH_TO_KEYFILE groupname={{ groupname }}
with_items: gce.instance_data
name: Manage new instances
hosts: "{{ groupname }}"
connection: ssh
sudo: True
roles:
- { role: webserver, port: "{{ port }}" }
--
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/28fa7149-29e5-46f7-ac90-fb79e67ac422%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi Peter
As Fred says, the variables are not in scope for both plays. You will need to declare your variables such that both plays can see them. You could put them into a separate file and reference it with vars_files in both plays, or you could pass them in as extra vars on the command line. You will not be able to put them into group_vars/ or host_vars/, as they are not able to be resolved at the time the hosts are matched.
Also, you can simplify your role call to
roles:
- { role: webserver, port: port }
(i.e. without interpolating the port var into a string)
Although the port variable will be in scope within the role just by declaring it in your play, so you can drop it altogether as a role parameter
roles:
- webserver
Regards
Tom