Hi Pavel,

I can only speak as a community maintainer.  However, from experience,
trying to pack extra logic like that into modules results in the code
becoming less reliable.  The "check" parameter you've suggested is
effectively duplicating the functionality of "when", while not being as
flexible.

My alternative suggestion would be to split the "test" shell task (which
you can set to always use `changed_when: False`) from the "update" shell
task and use the pre-existing when controls to decide if the "update" shell
task even needs to run.

"""
- name: Check record
  shell: record-is-present
  register: check
  changed_when: False

- name: Add record
  shell: add-record
  register: result
  when: check.rc == 0
"""

This also has the advantage that it's also very clear why things happened
and you can access the output of both shell commands.

While I do sometimes miss the "check" type logic that's available with
Puppet, it can also cause confusion in and of itself, and is often a sign
that something would be much better handled as a custom module rather than
a shell task.


Mark

On Wed, 22 Feb 2023 at 12:41, Pavel Brezina <pbrez...@redhat.com> wrote:

> Hi,
> this is about https://github.com/ansible/ansible/issues/80025 which was
> closed without giving a reason.
>
> Having this feature implemented would help shell/command become really
> idempotent a giving correct result. It should be also quite simple to
> implement, given how the command module is written.
>
> I would like to know the reason, why is Ansible team not interested in
> this functionality.
>
> Thanks,
> Pavel
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-devel+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-devel/2ec7f7c8-b337-45f1-9bfa-919b427e8dcan%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-devel/2ec7f7c8-b337-45f1-9bfa-919b427e8dcan%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
Mark Chappell
Senior Principal Systems Engineer, Red Hat GmbH
Tel: +49 89 205 071 284   Mob: +49 172 7 32 16 87
Fax: +49 89 205 071 111
GnuPG: 6FEA E991 09E8 6CA2 0498  8696 D9E0 55E6 C46E A90E

Red Hat GmbH <https://www.redhat.com/de/global/dach>,
Sitz: Werner von Siemens Ring 12, D-85630 Grasbrunn
Handelsregister: Amtsgericht München, HRB 153243,
Geschäftsführer: Ryan Barnhart, Charles Cachera, Michael O'Neill, Amy Ross

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-devel/CAMCBCy%2BN7ATL7Ws7ibueOTYL9J%3DFXeDTWpsGRMhWc9g_DXmzYA%40mail.gmail.com.

Reply via email to