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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/5f6a9570-cd45-430b-b4c3-0a7e5afa1d25%40googlegroups.com.

Reply via email to