ansible always reports changed

Hi

I have ansible 2.6.5 and I notice one strange think. If I use hard code path for “item.dest” then reports no changed. Change is reported only if I change something inside plugins which is OK

  • name: install plugins
    copy:
    src: “{{ item.src }}”
    dest: “{{ item.dest }}”
    mode: 0755
    owner: root
    group: root
    with_items:
  • { src: mk_logins,dest: ‘/usr/lib/check_mk_agent/plugins’}
  • { src: symantec_av,dest: ‘/usr/lib/check_mk_agent/plugins’}

TASK [check-mk-agent : install plugins] ***********************************************************************************
ok: [rhl1] => (item={u’dest’: u’/usr/lib/check_mk_agent/plugins’, u’src’: u’mk_logins’})
ok: [rhl1] => (item={u’dest’: u’/usr/lib/check_mk_agent/plugins’, u’src’: u’symantec_av’})

but if I use variable for path “/usr/lib/check_mk_agent/plugins” then ansible always reports changed when I run ansible-playbook

variable in defaults/main.yml

plugins_dir: ‘usr/lib/check_mk_agent/plugins’

  • name: install plugins
    copy:
    src: “{{ item.src }}”
    dest: “{{ item.dest }}”
    mode: 0755
    owner: root
    group: root
    with_items:
  • { src: mk_logins,dest: plugins_dir }
  • { src: symantec_av,dest: plugins_dir }

TASK [check-mk-agent : install plugins] ***********************************************************************************
changed: [rhl1] => (item={u’dest’: u’plugins_dir’, u’src’: u’mk_logins’})
changed: [rhl1] => (item={u’dest’: u’plugins_dir’, u’src’: u’symantec_av’})

So question is why is this happen?

Thanks

variable in defaults/main.yml

plugins_dir: 'usr/lib/check_mk_agent/plugins'

- name: install plugins
  copy:
    src: "{{ item.src }}"
    dest: "{{ item.dest }}"
    mode: 0755
    owner: root
    group: root
  with_items:
    - { src: mk_logins,dest: plugins_dir }
    - { src: symantec_av,dest: plugins_dir }

Your plugins_dir in these two last line is not a variable since it's missing {{ }} around them so they are literally the string plugins_dir.

TASK [check-mk-agent : install plugins]
***********************************************************************************
changed: [rhl1] => (item={u'dest': u'plugins_dir', u'src': u'mk_logins'})
changed: [rhl1] => (item={u'dest': u'plugins_dir', u'src': u'symantec_av'})

As you can see here dest contains 'plugins_dir' and not the content of the variable plugins_dir.

Thanks it works now.

  • name: install plugins
    copy:
    src: “{{ item.src }}”
    dest: “{{ item.dest }}”
    mode: 0755
    owner: root
    group: root
    with_items:
  • { src: mk_logins,dest: “{{ plugins_dir }}” }
  • { src: symantec_av,dest: “{{ plugins_dir }}” }