Thank you for the reply.. I thought if I set host all at the top and then set the facts for host all it would work. I guess I would have to have localhost in my inventory file correct?
I am just trying to launch a ec2 instance in my playbook On Saturday, 30 May 2020 23:35:14 UTC-4, Dick Visser wrote: > > Facts are set per host. You mix all with localhost. > > What are you trying to do? > > > On Sat, 30 May 2020 at 23:47, Andrew Morgan <[email protected] > <javascript:>> wrote: > >> Hello All, >> >> I am having an issue when I set a fact, I am not able to see that fact >> after I have another host block in my playbook. I get the error variable is >> undefined. The issue occurs in my - name: Launch instance >> >> >> --- >> - hosts: all >> become: yes >> #connection: local >> >> tasks: >> >> - name: Get Instance info >> register: ec2_facts >> >> >> - name: setting fact for Security group >> set_fact: >> SERCURITYGROUP : "{{ item.group_name }}" >> with_items: "{{ ec2_facts.instances[0].network_interfaces[0].groups >> }}" >> >> >> - hosts: localhost >> gather_facts: False >> vars: >> keypair: ansible >> instance_type: m1.small >> image: "{{ ami_id }}" >> region: us-east-1 >> subnet: "{{ SUBNETID }}" >> >> tasks: >> >> - name: Launch instance >> ec2: >> key_name: "{{ keypair }}" >> group: "{{ SERCURITYGROUP }}" >> instance_type: "{{ instance_type }}" >> image: "{{ image }}" >> wait: true >> region: "{{ region }}" >> vpc_subnet_id: "{{ subnet}}" >> assign_public_ip: yes >> register: ec2 >> >> >> TASK [Launch instance] >> ********************************************************************************************* >> fatal: [localhost]: FAILED! => >> msg: |- >> The task includes an option with an undefined variable. The error was >> : 'SERCURITYGROUP' is undefined >> >> >> I have set the variable as a fact, so I am not sure why I cannot call it >> with another --host stanza . >> >> -- >> 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] <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/ansible-project/5f6a9570-cd45-430b-b4c3-0a7e5afa1d25%40googlegroups.com >> >> <https://groups.google.com/d/msgid/ansible-project/5f6a9570-cd45-430b-b4c3-0a7e5afa1d25%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- > Sent from a mobile device - please excuse the brevity, spelling and > punctuation. > -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/b416d54d-9d94-4d6f-8c24-023bc5d4162e%40googlegroups.com.
