I have a simple playbook that I'm testing with in an attempt to update a 
file that has some test strings mapped to mac addresses. When I run my 
playbook I can only seem to get one of my two hosts to write the test 
string into the playbook and not both. If I run it a second time, I can get 
the second host in there.

The plybook looks similar to the following:

---
- name: Update File
  hosts:
    - test_group
  connection: local
  gather_facts: no
  
  vars:
    user_home: "{{ lookup('env', 'HOME') }}"
    config_file: "{{ inventory_hostname }}.conf"
    
  tasks:
    - name: Load device vars from config file
      include_vars: "{{ user_home }}/{{ config_file }}"
      
    - name: Update test file
      lineinfile:
        path: /var/tmp/test.yaml
        regexp: "^\ \ test[.-]{{ test_string|lower }}:.*"
        line: "  test-{{ test_string|lower }}: {{ mac }}"

The config file has multiple variables for each host in it including the 
'test_string' and 'mac'.

My test_group has two hosts:

[test_group]
host1
host2


And each host has a config file in my home directory 'host[12].conf' with 
the following:

host1.conf
test_string: abc
mac: 01:23:45:67:89:ab

host2.conf
test_string: xyz
mac: ab:09:87:65:43:21

When run, I expect to have both hosts with an entry in /var/tmp/test.yaml 
similar to:

mac_list:
  test-abc: 01:23:45:67:89:ab
  test-xyz: ab:09:87:65:43:21




But I can only get one host to update at a time although the task, when run 
in debug mode, showing that both hosts were changed. I have to run it a 
second time to get lineinfile to write the second host

What am I missing to make this work for both hosts?

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/427cf688-1828-4bdd-b648-d7423a1723ec%40googlegroups.com.

Reply via email to