Manage Inventory in Ansible

59 views
Skip to first unread message

satheesh kumar

unread,
Aug 19, 2015, 12:21:04 PM8/19/15
to Ansible Project
Hi,

Currently i'm using static inventory in ansible and have folder structure like Inventories/inv1, Inventories/inv2, etc..

# Inventories/inv1
[atlanta]
xyz.com

[europe]
abc.com

I need to have group variables for production in a way like Inventories/group_vars/production which is specific to Prod.

#Inventories/group_vars/production
---

url: 'jnp://mqendpoint.company.com:1099'
env: 'Production'


How can I glue these two files into a third inventory file Inventories/production.

What I tried is
#Inventories/production
[production:children]
atlanta
europe

I am getting error as  child group is not defined:atlanta, europe

Any ideas?

Serge van Ginderachter

unread,
Aug 19, 2015, 12:25:56 PM8/19/15
to ansible...@googlegroups.com
# Inventories/inv1
[atlanta]
xyz.com

[europe]
abc.com

I need to have group variables for production in a way like Inventories/group_vars/production which is specific to Prod.

#Inventories/group_vars/production
---

url: 'jnp://mqendpoint.company.com:1099'
env: 'Production'


How can I glue these two files into a third inventory file Inventories/production.

What I tried is
#Inventories/production
[production:children]
atlanta
europe

I am getting error as  child group is not defined:atlanta, europe

​Because eacht ini file is parsed as if it was a unique inventory.

Just add
---
[atlanta]​
 
​[europe]​

in #Inventories/production
and you'l be good


Any ideas?

--
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/da821773-8bf0-4704-8696-ca3a2ada935a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

satheesh kumar

unread,
Aug 19, 2015, 12:58:48 PM8/19/15
to Ansible Project
I added the same


---
[atlanta]​ 
​[europe]​

in #Inventories/production

and when i run playbook # ansible-playbook -i Inventories/production, it doesn't picks the inventory details.

Currently my inventory is

|----Inventories
|         |-----group_vars
|         |           |---production
|         |-----Inventory1
|         |-----Production
|----Playbooks
|         |-----test.yml
|-----roles
|         |-----copy_template
|                     |-----tasks/main.yml
                      |-----templates/copy.js.j2



#Inventories/group_vars/production
---

url: 'jnp://mqendpoint.company.com:1099'
env: 'Production'


#Inventories/inventory1
[smtp]

server1 ansible_ssh_host=server1.cloudapp.net  ansible_ssh_port=22
server2 ansible_ssh_host=server1.cloudapp.net  ansible_ssh_port=23

[smtp:vars]
ansible_ssh_user=testuser
ansible_ssh_private_key_file=/home/testuser/smtp-key.pem


#Inventories/production
---
[smtp]



#Playbooks/test.yml
---
- hosts: "{{ hosts }}"
  remote_user: testuser
  sudo: yes
  roles:
      - copy_template

#roles/copy_template/tasks/main.yml
---

- name: Upload config file
  template: src=copy.js.j2  dest=/home/testuser/test.js owner=root mode=0664
  sudo: true


#roles/copy_template/templates/copy.js.j2
// Configuration parameters
var environment = '{{env}}';
var url = '{{url}}';


I run the playbook using # ansible-playbook -i Inventories/production Playbooks/test.yml --extra-vars "hosts=smtp"

But no hosts matched in my case. Can you please help


Serge van Ginderachter

unread,
Aug 19, 2015, 1:08:14 PM8/19/15
to ansible...@googlegroups.com

On 19 August 2015 at 18:58, satheesh kumar <infosath...@gmail.com> wrote:
I run the playbook using # ansible-playbook -i Inventories/production Playbooks/test.yml --extra-vars "hosts=smtp"


​Now you are pointing your inventory to the production file which only holds an empty group 'smtp'​.

satheesh kumar

unread,
Aug 19, 2015, 1:43:11 PM8/19/15
to Ansible Project
Can you help me how to refer the group inside Inventories/Inventory1 ?

Serge van Ginderachter

unread,
Aug 19, 2015, 5:17:41 PM8/19/15
to ansible...@googlegroups.com

On 19 August 2015 at 19:43, satheesh kumar <infosath...@gmail.com> wrote:
Can you help me how to refer the group inside Inventories/Inventory1 ?


​        ​
-
​i Inventories

don't do -i Inventories/production - at least not how your example is laid out.​


Reply all
Reply to author
Forward
0 new messages