Ansible Inventory file

1,142 views
Skip to first unread message

Deepak Sharma

unread,
Feb 1, 2019, 4:01:24 AM2/1/19
to Ansible Project

Hi Everyone,

I am new to Ansible , I have created new inventory yml file with below details .

KafkaNonprodservers:
  hosts:
   ansible_user : abc

but I am getting below error 

+ ansible-inventory -i ./ansible/Hosts.yml --list [WARNING]: Skipping unexpected key (ansible_user) in group (KafkaNonprodservers), only "vars", "children" and "hosts" are valid 
{ 

Can you please guide me,.

Regards,
Deepak

Keif Gwinn

unread,
Feb 1, 2019, 7:35:01 AM2/1/19
to ansible...@googlegroups.com
Hi Deepak,

ansible_user is a special variable used by ansible for ssh, part of the main config. If you use a different variable name in your config file you should be fine.


--
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/fb100f1b-3641-4267-8e35-e187c341631a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Keif Gwinn

Keif Gwinn

unread,
Feb 1, 2019, 11:12:31 AM2/1/19
to ansible...@googlegroups.com
sorry got the wrong idea, I'm also new to ansible.

The variables you're adding need to go under a vars section

KafkaNonprodservers:
  hosts:
      - abc.abc.com:2022
      - abd.abd.com:2022
  vars:
    ansible_user: abc

[keif@ansible-lab ansible]$ ansible-inventory -i keif/test.yml --list
{
    "KafkaNonprodservers": {
        "hosts": [
        ]
    },
    "_meta": {
        "hostvars": {
            "abc.abc.com:2022 abd.abd.com:2022": {
                "ansible_user": "abc"
            }
        }
    },
    "all": {
        "children": [
            "KafkaNonprodservers",
            "ungrouped"
        ]
    },
    "ungrouped": {}
}

--
Keif Gwinn

Keif Gwinn

unread,
Feb 1, 2019, 11:23:21 AM2/1/19
to ansible...@googlegroups.com
KafkaNonprodservers:
hosts:
vars:
ansible_user: abc
--
Keif Gwinn

Hugo Gonzalez

unread,
Feb 1, 2019, 2:20:54 PM2/1/19
to ansible...@googlegroups.com

Hello Deepak,

You're not following the right syntax for a YML inventory. Check the following link:

https://docs.ansible.com/ansible/latest/plugins/inventory/yaml.html

I don't know what you're trying to do with the " 2022" string there. It's not valid yaml.

According to the docs in the link. You probably have to do something like this.

$ cat lala.yml
KafkaNonprodservers:
  hosts:
      abc.abc.com:
      abd.abd.com:
  vars:
      ansible_user: abc

You can always analyze your inventory file with ansible-inventory, like this:

$ ansible-inventory  -i lala.yml  --graph --vars
@all:
  |--@KafkaNonprodservers:
  |  |--abc.abc.com
  |  |--abd.abd.com
  |  |--{ansible_user = abc}
  |--@ungrouped:

Hope that helps,


Hugo

--
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/fb100f1b-3641-4267-8e35-e187c341631a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

Hugo F. gonzalez

Senior Consultant

Red Hat LATAM

Deepak Sharma

unread,
Feb 1, 2019, 3:05:34 PM2/1/19
to ansible...@googlegroups.com
Hi Hugo,

Thanks a lot , now it is working fine.

Regards,
Deepak

Deepak Sharma

unread,
Feb 1, 2019, 3:07:33 PM2/1/19
to ansible...@googlegroups.com
Thanks Keif,

I have added vars as port and users, after that it is working fine.

Regards,
Deepak

Reply all
Reply to author
Forward
0 new messages