1

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.

Thomas Hirsch
  • 2,102
  • 3
  • 19
  • 39
shashi
  • 36
  • 4

1 Answers1

0

This is because of the cache... Go to ~/.ansible/tmp and delete inventory_test.cache file.

Also, this is helpful answer if you able edit playbook...

ozlevka
  • 1,988
  • 16
  • 28