$ ansible --version
ansible 2.2.0 (devel 7af47a3886) last updated 2016/04/28 13:40:56 (GMT -500)
lib/ansible/modules/core: (detached HEAD e78ee3b128) last updated 2016/04/28 13:40:56 (GMT -500)
lib/ansible/modules/extras: (detached HEAD ca310f3d15) last updated 2016/04/28 13:40:56 (GMT -500)
config file =
configured module search path = Default w/o overrides
The tasks
- name: configure IP address
template: >
src=“etc/sysconfig/network/ifcfg.j2”
dest=“/etc/sysconfig/network/ifcfg-{{ item.device }}”
with_items: - “{{ network_interfaces }}”
The network_interfaces variable
network_interfaces:
- device: “eth1”
name: “domain1.com”
bootproto: “static”
address: “192.168.100.1”
netmask: “255.255.255.0”
gateway: “192.168.100.254” - device: “eth2”
name: “domain2.com”
bootproto: “static”
address: “172.18.28.201”
netmask: “255.255.0.0”
The template file (ifcfg.j2)
STARTMODE=‘auto’
USERCONTROL=‘no’
BOOTPROTO=‘{{ item.bootproto }}’
IPADDR=‘{{ item.address }}’
NETMASK=‘{{ item.netmask }}’
{% if item.broadcast is defined %}
BROADCAST=‘{{ item.broadcast }}’
{% endif %}
{% if item.ethool_options is defined %}
ETHTOOL_OPTIONS=‘’
{% endif %}
{% if item.mtu is defined %}
MTU=‘’
{% endif %}
{% if item.name is defined %}
NAME=‘{{ item.name }}’
{% endif %}
{% if item.network is defined %}
NETWORK=‘’
{% endif %}
{% if item.remote_ipaddr is defined %}
REMOTE_IPADDR=‘’
{% endif %}
Every run of Ansible says eth1 and eth2 have changed.
I copied the ifcfg-eth1 to ifcfg-eth1.bak and ran Ansible again. The diff of the files shows nothing different.
What determines if the file needs to be “changed”?