i am using "shell:" to get some data by looping over "with_items:" and registering it as another variable. Later using "lineinfile:" i am trying to apply the contents of earlier variable,but not able to use "{{variable.stdout}}" as it is showing as undefined in "with_items:"
Is there a way to tell ansible that for "variable.stdout" don't look in "with_items:"
---
- include_vars: /root/template.yml
- name: Getting MAC
shell: "cat /sys/class/net/{{item.name}}/address"
register: mac
with_items:
- "{{ interfaces_ipv4 }}"
- name: Setting MAC
lineinfile:
state=present
dest=/etc/sysconfig/network-scripts/ifcfg-{{item.name}}
regexp='^HWADDR=.*'
line="HWADDR={{mac.stdout}}"
with_items:
- "{{ interfaces_ipv4 }}"
tags:
- set_mac
Contents of variable file
#/root/tempplate.yml
- name: ens35
bootproto: dhcp
- name: ens34
bootproto: none
When executing:
TASK: [mac | Setting MAC] ***************************************************** fatal: [192.168.211.146] => One or more undefined variables: 'dict' object has no attribute 'stdout'
FATAL: all hosts have already failed -- aborting
templatemodule instead oflineinfile. The latter is an antipattern; it tends towards substantial complexity and pain.