add_host

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? :slight_smile:
Thank you!

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.