i´m new to ansible and try to automate server interface configuration. Just something default like ip, gateway, dns and so on.
I´ve a task, called config_interfaces;
---
- name: nmcli add Ethernet
community.general.nmcli:
type: ethernet
conn_name: '{{ item.conn_name }}'
ip4: '{{ item.ip4 }}'
gw4: '{{ item.gw4 }}'
dns4: '{{ item.dns4 }}'
never_default4: '{{ item.default4 }}'
state: present
with_items:
- '{{ nmcli_ethernet }}'
register: add_interface_output
- name: restart interfaces
command: bash -c "nmcli con up {{ add_interface_output.conn_name }}"
when: add_interface_output.changed == true
with_items: "{{ add_interface_output.changed }}"
Then I have my group_vars file, which contains the nmcli_etherrnet variable;
---
nmcli_ethernet:
- conn_name: ens33
ifname: ens33
ip4: '{{ config_interfaces.ip_lan }}'
gw4: '{{ ip_lan_gw }}'
dns4: '{{ ip_lan_dns }}'
default4: no
- conn_name: ens37
ifname: ens37
ip4: '{{ config_interfaces.ip_trans }}'
default4: yes
- conn_name: eth1
ifname: eth1
ip4: '{{ config_interfaces.ip_exch1 }}'
default4: yes
- conn_name: eth2
ifname: eth2
ip4: '{{ config_interfaces.ip_exch2 }}'
default4: yes
ip_lan_gw: "192.168.226.2"
ip_lan_dns:
- 8.8.8.8
- 8.8.4.4
never_default4: yes
It´s always failing with
FAILED! => {"msg": "'nmcli_ethernet' is undefined"}
I´m searching for days now and don´t know where i missunderstand the with_items function. I bet this is just a completely small issue, but i dind´t get it.
Please help