HiveBrain v1.2.0
Get Started
← Back to all entries
snippetMinor

How to use edited inventory file?

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
fileinventoryhowediteduse

Problem

I have workflow with 2 templates. First I add new host to my hosts.ini file:

- name: Add to host file
     blockinfile:
       path: /var/lib/awx/projects/_52__glusterfs/hosts.ini
       block: |
         gluster1 ansible_user= ansible_host=


And second I wait for host up:

---
- name: Weit befor all hosts ssh up
  hosts: localhost
  tasks:
   - name: Test 1
     shell: cat hosts.ini
   - name: Test 2
     shell: cat /var/lib/awx/projects/_52__glusterfs/hosts.ini
   - name: Test 3
     shell: cat ansible.cfg
   - name: Wait for hosts up
     wait_for:
       host: gluster1
       port: 22


But i get eror:

[WARNING]: provided hosts list is empty, only localhost is available. Note
that the implicit localhost does not match 'all'


So output from tests in template 2 is (pseudocode output):

shell: cat hosts.ini
>>> 
[gluster]


shell: cat /var/lib/awx/projects/_52__glusterfs/hosts.ini
>>> 
[gluster]
gluster1 ansible_user= ansible_host=


shell: cat ansible.cfg
>>> 
[defaults]
inventory = /var/lib/awx/projects/_52__glusterfs/hosts.ini
host_key_checking = false

[ssh_connection]
ssh_args = -o ControlMaster=auto -o ControlPersist=60s -o UserKnownHostsFile=/dev/null

[inventory]
enable_plugins = host_list, script, auto, yaml, ini, toml


Why I have empty hosts.ini in my execute directory and why ansible use it instead of /var/lib/awx/projects/_52__glusterfs/hosts.ini in my ansible.cfg file?

Solution

You have this in your config file:

[inventory]
enable_plugins = host_list, script, auto, yaml, ini, toml


Do you really need all these plugins? If not, they'll just add time to your processing. There is also a small chance that one of them is successfully parsing your inventory file as an empty inventory. And the documentation states that


Once an inventory plugin succeeds at parsing a source, any remaining inventory plugins will be skipped for that source.

If you do not need those plugins, I'd comment that line (or rework it to remove some of the items).

Also, are you sure that it is using the local hosts.ini? The command ansible-config might help confirming that.

Regarding your first question ("Why I have empty hosts.ini in my execute directory"), there is nothing in your playbooks pointing to that file being created or modified. Did you mean to have it modified? Or you don't know how it was created? The question there is not clear.

Code Snippets

[inventory]
enable_plugins = host_list, script, auto, yaml, ini, toml

Context

StackExchange DevOps Q#9893, answer score: 2

Revisions (0)

No revisions yet.