[ansible-project] Re: How to use external variable inside an ansible inventory file.

2015-12-26 Thread pixel fairy
theres probably an easier way, but since your setting up for a dynamic 
inventory, you might as well use it.

http://docs.ansible.com/ansible/developing_inventory.html

heres an example in python for lxc containers. 

#!/usr/bin/env python

import yaml
import json

with open('containers.yml') as fp:
c = yaml.load(fp)
containers = c['containers']

inventory = {
'containers': { 'hosts': [] },
'_meta': { 'hostvars': {} }
}

for k, v in containers.items():
inventory['containers']['hosts'].append(k)
if 'groups' in v:
for group in v['groups']:
if group not in inventory:
inventory[group] = { 'hosts':[] }
inventory[group]['hosts'].append(k)
inventory['_meta']['hostvars'][k] = {}
inventory['_meta']['hostvars'][k]['ansible_ssh_host'] = v['address']

print(json.dumps(inventory,indent=2))


and the containers,

containers:
  vpn:
address: 192.168.114.4
forwards:
- { transport: udp, host: 1194, container: 1194 }
  reverseproxy:
address: 192.168.114.10
forwards:
- { transport: tcp, host: 80, container: 80 }
- { transport: tcp, host: 443, container: 443 }
  web1:
hostname: web1.example.lan
address: 192.168.114.11
cnames:
- moreweb.example.lan
- another.example.lan
groups:
  - web
  web2:
hostname: web2.example.lan
address: 192.168.114.12
groups:
  - web







On Monday, December 14, 2015 at 11:30:25 PM UTC-8, anoop@tarams.com 
wrote:
>
> Hi,
>
> I have an inventory file 'inventory/localhost' and contains;
> [localhost]
> "{{MYSITE_NAME}}-local.com"ansible_ssh_port=
>
>
> Lets say 'MYSITE_NAME' is a variable defined in some file. I need to 
> access this inside my inventory file. Please suggest some solution.
>

-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/9fca2acb-8dcc-4e44-857e-124bfb016b1b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: How to use external variable inside an ansible inventory file.

2015-12-15 Thread anoop . kolari
Any suggestion guys??


On Tuesday, December 15, 2015 at 1:00:25 PM UTC+5:30, anoop@tarams.com 
wrote:
>
> Hi,
>
> I have an inventory file 'inventory/localhost' and contains;
> [localhost]
> "{{MYSITE_NAME}}-local.com"ansible_ssh_port=
>
>
> Lets say 'MYSITE_NAME' is a variable defined in some file. I need to 
> access this inside my inventory file. Please suggest some solution.
>

-- 
 =
DISCLAIMER: The information in this message is confidential and may be 
legally privileged. It is intended solely for the addressee. Access to this 
message by anyone else is unauthorized. If you are not the intended 
recipient, any disclosure, copying, or distribution of the message, or any 
action or omission taken by you in reliance on it, is prohibited and may be 
unlawful. Please immediately contact the sender if you have received this 
message in error. Further, this e-mail may contain viruses and all 
reasonable precaution to minimize the risk arising there from is taken by 
Tarams. Tarams is not liable for any damage sustained by you as a result of 
any virus in this e-mail. All applicable virus checks should be carried out 
by you before opening this e-mail or any attachment thereto.
Thank you - Tarams Software Technologies Pvt.Ltd.
=

-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/692cf118-3399-4443-a0db-540184f460fc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.