template: shows change every time but no change?

1,136 views
Skip to first unread message

Bob Tanner

unread,
Apr 28, 2016, 7:32:30 PM4/28/16
to Ansible Project
$ 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"? 

Matt Martz

unread,
Apr 28, 2016, 8:00:08 PM4/28/16
to ansible...@googlegroups.com
Have you tried running Ansible with --diff to see what it says is changing?

--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/8e54b3d7-7f8c-4d33-9885-832349924926%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Matt Martz
@sivel
sivel.net

Bob Tanner

unread,
Apr 29, 2016, 12:16:56 AM4/29/16
to Ansible Project
Thank you for the advise. 

It looks like it's not an Ansible thing. It looks like only happens when I run the Ansible playbook via Vagrant.

Thanks again.
Reply all
Reply to author
Forward
0 new messages