N
N
Nikon_NLG2015-11-16 11:43:46
Ansible
Nikon_NLG, 2015-11-16 11:43:46

What's wrong with dynamic inventory?

Hello. Internally, the company uses its own hostnames, such as dev-nginx, dev-memcached, etc.
Created a dynamic inventory that returns something like this list:

{
    "_meta": {
        "hostvars": {
            "dev-nginx": {
                "ansible_ssh_host": "ip-192-168-1-1.internal.tld",
                "ec2_private_dns_name": "ip-192-168-1-1.internal.tld"
            },
            "dev-memcached": {
                "ansible_ssh_host": "ip-192-168-1-2.internal.tld",
                "ec2_private_dns_name": "ip-192-168-1-2.internal.tld"
            },
        }
    }
....
    "dev-nginx": [
        "ip-192-168-1-1.internal.tld"
    ],
    "dev-memcached": [
        "ip-192-168-1-2.internal.tld"
    ],

When trying to play a simple playbook:
---
- host: dev-nginx
  - name echo memcached
  - shell: echo {{ hostvars[groups['dev-memcached']][0]['ansible_fqdn'] }}

Crashes with an error
fatal: [ip-192-168-1-1.internal.tld] => One or more undefined variables: ansible.runner.HostVars object has no element [u'ip-192-168-1-2.internal.tld']

I also added ip-192-168-1-2.internal.tld to _meta.hostvars, but it didn't help. How do you get the playbook to work? Or did I add ip-192-168-1-2.internal.tld incorrectly?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question