I have created a simple dynamic inventory python which prints JSON to standard output mentioned below, but Ansible inventory does not refresh.
Command: ansible-playbook playbooks/deploy.yaml -i playbook/inventory_test.py
Inventory JSON:
{
'python_hosts': {
'hosts': ['10.220.21.122', '10.220.21.278'],
'vars': {
'ansible_ssh_user': 'projectuser',
}
},
'_meta': {
'hostvars': {
'10.220.21.122': {
'host_specific_var': 'testhost'
},
'10.220.21.278': {
'host_specific_var': 'towerhost'
}
}
}
}
I also tried this:
- hosts: localhost
tasks:
- name: test
script: ./inventory_test.py
- name: Refresh inventory
meta: refresh_inventory
- name: print new inventory
debug:
var: groups
But inventory still does not refresh automatically.
Ansible version is 2.6.4
Any help on this is really appreciated.