Dynamic Inventory AWS EC2 + group_vars

1,165 views
Skip to first unread message

sirkubax

unread,
Jun 11, 2015, 8:11:33 AM6/11/15
to ansible...@googlegroups.com
Hi

ansible 1.9.1


I'd like to load some variables for newly created instances from my static inventory.

I do create some EC2 instances with a playbook (as in basic example):

- hosts: localhost
  connection: local
  gather_facts: False

  tasks:

    - name: Provision a set of instances
      ec2:
          region: eu-central-1
          key_name: kuba_aws
          group: default
          instance_type: t2.micro
          image: ami-accff2b1
          vpc_subnet_id: subnet-xxxxxx
          wait: yes
          exact_count: 3
          count_tag:
             Name: Demo
          instance_tags:
             Name: Demo
             test_tag: Demo
      register: ec2


I do have static group_vars defined:
cat group_vars/tag_Name_Demo
---
ansible_ssh_private_key_file: ~/.ssh/mykey
ansible_ssh_user: ubuntu

But when I lunch:
ansible -m ping tag_Name_Demo -vvv

<172.16.1.12> ESTABLISH CONNECTION FOR USER: xxxxx


So the files are not read. I thought that the inventories are not combined, so I did create directory combining static and dynamic inventory, but no luck
ls ~/inv/
ec2.py  inventory-qa.ini

ansible -m ping tag_Name_Demo -vvv -i ~/inv/
<172.16.1.12> ESTABLISH CONNECTION FOR USER: xxxxx

I was sure, that ansible would match group_vars from static inventory and assign proper variables for groups in dynamic_inventory ...
Any suggestions - probably there is some step missing?

sirkubax

unread,
Jun 11, 2015, 9:59:09 AM6/11/15
to ansible...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages