Ansible + AWS documentation

86 views
Skip to first unread message

I like ansible

unread,
Nov 11, 2015, 6:00:50 PM11/11/15
to Ansible Project
thanks for the documentation about how to manage AWS ec2 dynamic inventory, in this example:
http://docs.ansible.com/ansible/intro_dynamic_inventory.html#example-aws-ec2-external-inventory-script

the doc is assuming that two separate accounts are used for dev vs production: hence different authentication used to connect.
another common aws approach is to have one account but multiple VPC (prod / staging / dev) and using tags.

would love to have some info written about this second approach one account with multiple VPCs

been trying to experiment with stuff like:

  hosts: "tag_stack_webserver: &tag_environment_production"


not sure if its the correct approach

wojtas

unread,
Nov 17, 2015, 5:17:27 AM11/17/15
to Ansible Project
Hi,
Is there a space between ":" and "&" ?
Is it is there delete it.
The formula You write is ok:
$ ansible -i /etc/ansible/ec2.py all -m ping --limit "tag_deployment_production:&tag_role_elasticsearch"
52.XX.XXX.XXX | success >> {
    "changed": false,
    "ping": "pong"
}

54.XX.XX.XXX | success >> {
    "changed": false,
    "ping": "pong"
}

and in playbook:
 ~ $ ansible-playbook -i /etc/ansible/ec2.py /tmp/ping.yml

PLAY [tag_deployment_production:&tag_role_elasticsearch] **********************

GATHERING FACTS ***************************************************************
ok: [54.XX.XX.XX]
ok: [52.XX.XXX.XXX]

TASK: [TEST PING] *************************************************************
ok: [54.XX.XX.XX]
ok: [52.XX.XXX.XXX]

PLAY RECAP ********************************************************************
52.XX.XXX.XXX               : ok=2    changed=0    unreachable=0    failed=0 

~ $ cat /tmp/ping.yml
---
- hosts: "tag_deployment_production:&tag_role_elasticsearch"
  tasks:
    - name: TEST PING
      action: ping

PLASE notice that is available in:

~ $ ansible --version
ansible 1.9.4
  configured module search path = /usr/share/ansible

I like ansible

unread,
Nov 21, 2015, 10:04:31 PM11/21/15
to Ansible Project
thanks, it worked as suggested, 

now I am trying create an inventory file for production and staging as suggested here in suggested here in article Static Groups of Dynamic Groups

production

[webservers]                                        

"tag_environment_staging:&tag_stack_webserver"   

                                                    


staging

[webservers]                                        

"tag_environment_production:&tag_stack_webserver"   

                                                    


but I am receiving error


Traceback (most recent call last):                                                          

  File "/usr/local/bin/ansible-playbook", line 324, in <module>                             

    sys.exit(main(sys.argv[1:]))                                                            

  File "/usr/local/bin/ansible-playbook", line 157, in main                                 

    inventory = ansible.inventory.Inventory(options.inventory, vault_password=vault_pass)   

  File "/Library/Python/2.7/site-packages/ansible/inventory/__init__.py", line 128, in __ini

t__                                                                                         

    self.parser = InventoryParser(filename=host_list)                                       

  File "/Library/Python/2.7/site-packages/ansible/inventory/ini.py", line 43, in __init__   

    self._parse()                                                                           

  File "/Library/Python/2.7/site-packages/ansible/inventory/ini.py", line 47, in _parse     

    self._parse_base_groups()                                                               

  File "/Library/Python/2.7/site-packages/ansible/inventory/ini.py", line 140, in _parse_bas

e_groups                                                                                    

    host = Host(name=hn, port=port)                                                         

  File "/Library/Python/2.7/site-packages/ansible/inventory/host.py", line 32, in __init__  

    self.set_variable('ansible_ssh_port', int(port))                                        

ValueError: invalid literal for int() with base 10: '&tag_stack_webserver'                  

Reply all
Reply to author
Forward
0 new messages