Skip to content

Instantly share code, notes, and snippets.

@zahna
Last active August 8, 2017 13:08
Show Gist options
  • Select an option

  • Save zahna/63783dba265269ea09a6c75e4d7bad62 to your computer and use it in GitHub Desktop.

Select an option

Save zahna/63783dba265269ea09a6c75e4d7bad62 to your computer and use it in GitHub Desktop.
initializing my ansible dynamic inventory data structure
# Initialize the inventory
inventory = {}
inventory['all'] = {'hosts': [], 'vars': {}}
inventory['_meta'] = {'hostvars': {}}
# Add localhost to inventory
inventory['all']['hosts'].append('localhost')
inventory['_meta']['hostvars']['localhost'] = {}
inventory['_meta']['hostvars']['localhost']['ansible_host'] = 'localhost'
inventory['_meta']['hostvars']['localhost']['ec2_public_dns_name'] = 'localhost'
inventory['_meta']['hostvars']['localhost']['ec2_public_ip_address'] = '127.0.0.1'
inventory['_meta']['hostvars']['localhost']['ec2_private_ip_address'] = '127.0.0.1'
inventory['_meta']['hostvars']['localhost']['ansible_connection'] = 'local'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment