Task reported as "changed" even if unchanged

20 views
Skip to first unread message

Marc Haber

unread,
May 16, 2020, 6:20:38 AM5/16/20
to ansible...@googlegroups.com
Hi,

the following task:

- name: configure systemd-timesyncd - check unit active
command:
argv:
- "systemctl"
- "is-enabled"
- "systemd-timesyncd"
check_mode: no
register: systemd_timesyncd_unit_enabled

yields a "changed" in the playbook output:

TASK [systemd-timesyncd : configure systemd-timesyncd - check unit active] *****
changed: [news1]
changed: [check]
changed: [slide]

Can I have ansible ignore that and output an "ok" instead for cosmetic reasons
and for statistics?

Greetings
Marc

--
-----------------------------------------------------------------------------
Marc Haber | "I don't trust Computers. They | Mailadresse im Header
Leimen, Germany | lose things." Winona Ryder | Fon: *49 6224 1600402
Nordisch by Nature | How to make an American Quilt | Fax: *49 6224 1600421

Jordan Borean

unread,
May 16, 2020, 6:24:08 AM5/16/20
to Ansible Project
You can use the changed_when task directive to control when a change is reported. If you want to say this will never create a change set ‘changed_when: false’

Jean-Yves LENHOF

unread,
May 16, 2020, 6:26:34 AM5/16/20
to ansible...@googlegroups.com
Hi,

you should better use systemd module instead of command to do what you
intended to do... This module is better at idempotence that command

Command is not idempotent by default, you have to do it (there are
different ways to do it), this is why you have some changes

Regards,

Marc Haber

unread,
May 16, 2020, 6:42:16 AM5/16/20
to ansible...@googlegroups.com
On Sat, May 16, 2020 at 03:24:08AM -0700, Jordan Borean wrote:
> You can use the changed_when task directive to control when a change is reported. If you want to say this will never create a change set ‘changed_when: false’

Thanks for answering my question, that was helpful!
Reply all
Reply to author
Forward
0 new messages