On Mon, 4 May 2020 13:26:41 -0700 (PDT)
Justin Nelson <[email protected]> wrote:

> The file contents after that pass are:
> 
>   1 macs:
>   2   test-host222: ab:09:87:65:43:21
> 
> And when I run it a second time:
> 
>   1 macs:
>   2   test-host222: ab:09:87:65:43:21
>   3   test-host111: 12:34:56:78:90:ab

It's working for me as expected

shell> cat test_01.conf 
test_string: abc
mac: 01:23:45:67:89:ab

shell> cat test_02.conf 
test_string: xyz
mac: ab:09:87:65:43:21

shell> cat pb.yml
- hosts:
    - test_01
    - test_02
  tasks:
    - include_vars: "{{ inventory_hostname }}.conf"
    - name: Update test file
      lineinfile:
        path: test-file
        regexp: "^\ \ test[.-]{{ test_string|lower }}:.*"
        line: "  test-{{ test_string|lower }}: {{ mac }}"
      delegate_to: localhost

shell> cat test-file 
shell> ansible-playbook pb.yml

PLAY [test_01,test_02]
***************************

TASK [include_vars]
***************************
ok: [test_01] ok: [test_02]

TASK [Update test file]
***************************
changed: [test_01 -> localhost]
changed: [test_02 -> localhost]

PLAY RECAP
***********************************************************************************
test_01                    : ok=2    changed=1    unreachable=0    failed=0
 skipped=0    rescued=0    ignored=0 test_02                    : ok=2
changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
  

shell> cat test-file 
  test-abc: 01:23:45:67:89:ab
  test-xyz: ab:09:87:65:43:21
--

-- 
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/20200504230430.469531c2%40gmail.com.

Attachment: pgp6a0twvWulh.pgp
Description: OpenPGP digital signature

Reply via email to