Answers: <p>It sounds like you need to gather facts again once you've updated the inventory. You start off with</p>
  
  <blockquote>
    <p>First I add new host to my hosts.ini file</p>
  </blockquote>
  
  <p>However, <strong>Ansible is not notified about this</strong> until you tell it that the inventory has changed. If this is done <em>during</em> a play, you should use the <a href="https://docs.ansible.com/ansible/latest/modules/add_host_module.html#add-host-module" rel="nofollow noreferrer">add_host</a> module:</p>
  
  <pre><code>- name: Add host gluster1 to group gluster
    add_host:
      name: gluster1
      groups: gluster
  </code></pre>
  
  <p>This will update Ansible's facts, <em>i.e.</em> it will contact the new host and find out everything about it, now that it knows it is in the <code>gluster</code> group.</p>
  
  <p>Note that then you should start a new play, against this host:</p>
  
  <pre><code>---
  - name: First play to build hosts
    hosts: localhost
    tasks:
      - name: Add host gluster1 to group gluster
        add_host:
          name: gluster1
          groups: gluster
      - name: Persist inventory
        blockinfile:
          path: /var/lib/awx/projects/_52__glusterfs/hosts.ini
          block: |
            gluster1 ansible_user=&lt;user&gt; ansible_host=&lt;ip&gt;
          state: present
  
  - name: Second play to do gluster things
    hosts: gluster  # This group now exists in Ansible's in-memory inventory
    tasks:
      - name: Wait for hosts up
        wait_for:
          host: gluster1
          port: 22
      - name: Be awesome
        debug:
          msg: "Awesomeness Achieved"
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2019-11-29T15:46:42.240Z
Answers: 2019-11-29T15:46:42.240Z
Answers: Bruce Becker
Answers: <p>You have this in your config file:</p>
  
  <pre><code>[inventory]
  enable_plugins = host_list, script, auto, yaml, ini, toml
  </code></pre>
  
  <p>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 <a href="https://docs.ansible.com/ansible/latest/plugins/inventory.html" rel="nofollow noreferrer">documentation</a> states that</p>
  
  <blockquote>
    <p>Once an inventory plugin succeeds at parsing a source, any remaining inventory plugins will be skipped for that source.</p>
  </blockquote>
  
  <p>If you do not need those plugins, I'd comment that line (or rework it to remove some of the items).</p>
  
  <p>Also, are you sure that it is using the local <code>hosts.ini</code>?  The command <code>ansible-config</code> might help confirming that.</p>
  
  <p>Regarding your first question ("<em>Why I have empty hosts.ini in my execute directory</em>"), 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.</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-11-29T02:53:54.737Z
Answers: 2019-11-29T02:53:54.737Z
Answers: caxcaxcoatl
Body: <p>I have workflow with 2 templates. First I add new host to my hosts.ini file:</p>
  
  <pre><code>- name: Add to host file
       blockinfile:
         path: /var/lib/awx/projects/_52__glusterfs/hosts.ini
         block: |
           gluster1 ansible_user=&lt;user&gt; ansible_host=&lt;ip&gt;
  </code></pre>
  
  <p>And second I wait for host up:</p>
  
  <pre><code>---
  - 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
  </code></pre>
  
  <p>But i get eror:</p>
  
  <pre><code> [WARNING]: provided hosts list is empty, only localhost is available. Note
  that the implicit localhost does not match 'all'
  </code></pre>
  
  <p>So output from tests in template 2 is (pseudocode output):</p>
  
  <pre><code>shell: cat hosts.ini
  &gt;&gt;&gt; 
  [gluster]
  </code></pre>
  
  <hr>
  
  <pre><code>shell: cat /var/lib/awx/projects/_52__glusterfs/hosts.ini
  &gt;&gt;&gt; 
  [gluster]
  gluster1 ansible_user=&lt;user&gt; ansible_host=&lt;ip&gt;
  </code></pre>
  
  <hr>
  
  <pre><code>shell: cat ansible.cfg
  &gt;&gt;&gt; 
  [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
  </code></pre>
  
  <p>Why I have empty hosts.ini in my execute directory and why ansible use it instead of <code>/var/lib/awx/projects/_52__glusterfs/hosts.ini</code> in my <code>ansible.cfg</code> file?</p>
  
Tags: <ansible><centos>
Title: How to use edited inventory file?
UserDisplayName: Danylo Mysko
ThreadText: # How to use edited inventory file?
  
  (Asked by: username_0 on 2019-11-22)
  
  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=<user> ansible_host=<ip>
  
  ```
  
  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=<user> ansible_host=<ip>
  
  ```
  
  ---
  
  ```
  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?
  
  **Tags:** ansible, centos
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2019-11-29. Score: 1 | Accepted answer
  
  It sounds like you need to gather facts again once you've updated the inventory. You start off with
  
  > First I add new host to my hosts.ini file
  
  However, **Ansible is not notified about this** until you tell it that the inventory has changed. If this is done *during* a play, you should use the [add\_host](https://docs.ansible.com/ansible/latest/modules/add_host_module.html#add-host-module) module:
  
  ```
  - name: Add host gluster1 to group gluster
    add_host:
      name: gluster1
      groups: gluster
  
  ```
  
  This will update Ansible's facts, *i.e.* it will contact the new host and find out everything about it, now that it knows it is in the `gluster` group.
  
  Note that then you should start a new play, against this host:
  
  ```
  ---
  - name: First play to build hosts
    hosts: localhost
    tasks:
      - name: Add host gluster1 to group gluster
        add_host:
          name: gluster1
          groups: gluster
      - name: Persist inventory
        blockinfile:
          path: /var/lib/awx/projects/_52__glusterfs/hosts.ini
          block: |
            gluster1 ansible_user=<user> ansible_host=<ip>
          state: present
  
  - name: Second play to do gluster things
    hosts: gluster  # This group now exists in Ansible's in-memory inventory
    tasks:
      - name: Wait for hosts up
        wait_for:
          host: gluster1
          port: 22
      - name: Be awesome
        debug:
          msg: "Awesomeness Achieved"
  
  ```
  
  
  ---
  
  ### Answer by username_2 on 2019-11-29. Score: 2
  
  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](https://docs.ansible.com/ansible/latest/plugins/inventory.html) 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.
  
  
  ---
  
  