--
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/8d21cfef-aa4f-4009-abc4-f9e2c235b8be%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
TASK: [Add new instance to host group] **************************************** fatal: [localhost -> 127.0.0.1] => One or more undefined variables: 'str object' has no attribute 'tagged_instances'
FATAL: all hosts have already failed -- aborting
---- name: Create EC2 Instances in VPC gather_facts: False hosts: local vars: security_group: my-sg instance_type: t2.medium image: ami-000111222 region: us-east-1 key_name: my-key attr: - { zone: us-east-1a, az: a, subnet: subnet-12345678 } - { zone: us-east-1b, az: b, subnet: subnet-23456789 } - { zone: us-east-1d, az: d, subnet: subnet-34567890 } tasks: - name: Create Nodes in VPC local_action: module: ec2 group: "{{ security_group }}" instance_type: "{{ instance_type }}" image: "{{ image }}" wait: "yes" vpc_subnet_id: "{{ item.subnet }}" region: "{{ region }}" zone: "{{ item.zone }}" key_name: "{{ key_name }}" instance_tags: Name: my-cool-tag-{{item.az}}-vpc exact_count: 1 count_tag: Name: my-cool-tag-{{item.az}}-vpc with_items: attr register: ec2
- name: dump output of ec2.results debug: var=ec2.results
- name: Add new instance to host group local_action: add_host hostname={{item.tagged_instances.private_ip}} groupname=launched with_items: - ec2.results
- name: Wait for SSH to come up local_action: wait_for host={{item.instances.private_ip}} port=22 delay=60 timeout=320 state=started with_items: - ec2.results
- name: Configure instances hosts: launched gather_facts: True sudo: True roles: - my-role
Okay, I understand that it only adds to the in-memory inventory, but that's not really the problem I'm having.
The problem I'm having is I can't get the IP. What I plan to do with the IP after I get it involves provisioning those hosts. I can't provision those hosts unless I get the IP from the current run which creates the host.
The step where I should be able to get the IP to add it to a group (in memory or otherwise) is failing.
TASK: [Add new instance to host group] ****************************************fatal: [localhost -> 127.0.0.1] => One or more undefined variables: 'str object' has no attribute 'tagged_instances'
FATAL: all hosts have already failed -- aborting
I think what you meant is
"run this task for all of ec2.results", but what you wrote is "run
this task for all of ['ec2.results']" (that's why it's complaining
about a string). with_items: ec2.results
Dash at the beginning of a line creates a list element in YAML
(that's why all tasks start with it :-))
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/e272d073-10a1-4895-a55d-cd69c7444268%40googlegroups.com.