add_host

18 views
Skip to first unread message

Patrick van Haren

unread,
Jul 17, 2016, 8:02:26 AM7/17/16
to Ansible Project
I try to add a hos to my inventory with the command below:

ansible localhost -m add_host -a "name=demo groups=containers"

This is the output:
localhost | SUCCESS => {
    "add_host": {
        "groups": [
            "containers"
        ],
        "host_name": "demo",
        "host_vars": {}
    },
    "changed": true
}

Unfortunately, Ansible doesn't add the new host to my inventory file which is defined in /etc/ansible/ansible.cfg
Also it doesn't work when I add "-i /path/to/hosts" in the command.

Anyone suggestions? :)
Thank you!

Dmitry Makovey

unread,
Jul 18, 2016, 10:49:07 AM7/18/16
to Ansible Project
add_host is meant to be used **runtime** thus it does not perform any operations making change persistent. Adding hosts to the inventory could be done via one of the "file" modules. 
Reply all
Reply to author
Forward
0 new messages