suppress "changed" for register'ed variables

31 views
Skip to first unread message

Matt Zagrabelny

unread,
Sep 26, 2023, 5:09:30 PM9/26/23
to ansible...@googlegroups.com
Greetings,

I currently register some variables via:

cat roles/configure_account_environment/tasks/main.yaml
---
# This playbook contains plays that will be run to configure an account.

-
    name: get {{ primary_user }} account's home directory
    shell: getent passwd {{ primary_user }} | cut -d ":" -f 6
    register: home_directory

...and when I run the playbook I get:

[...]
TASK [configure_account_environment : get root account's home directory] *********************
changed: [zed]

PLAY RECAP ***********************************************************************************
zed                        : ok=23   changed=2    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0
[...]

Having variables that get registered show up as "changed" feels misleading to me. Nothing is "changing" on the target node, I'm just getting some information from that system.

Is there a way to mark registered variables as something other than "changed" in the output of the playbook run?

Thanks for any hints and help!

-m

Richard Megginson

unread,
Sep 26, 2023, 5:30:27 PM9/26/23
to ansible...@googlegroups.com
--
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 view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAOLfK3VTp8dU%3DzBhL%3Dy%3DSuF1ZcQ5wh3gVPEK3xNMc24yvG4kKg%40mail.gmail.com.

Matt Zagrabelny

unread,
Sep 26, 2023, 7:09:02 PM9/26/23
to ansible...@googlegroups.com
Thanks for the help Richard!

Any ideas on changing "skipped" to "ok":

[...]

TASK [common : set editor to vim] ************************************************************************************************************************************************************
skipping: [zed]

[...]

PLAY RECAP ***********************************************************************************************************************************************************************************
zed                        : ok=23   changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0

Again, thank you for the great assistance.

Cheers,

-m

Richard Megginson

unread,
Sep 26, 2023, 8:00:54 PM9/26/23
to ansible...@googlegroups.com
Check the `when:` condition on the skipped task.  Why is the condition `false`?

Matt Zagrabelny

unread,
Sep 26, 2023, 8:18:03 PM9/26/23
to ansible...@googlegroups.com
Here are the two tasks:

-
    name:         get editor realpath
    shell:        realpath /usr/bin/editor
    register:     editor_realpath
    changed_when: False
    tags:
        - vim

-
    name:    set editor to vim
    command: update-alternatives --set editor /usr/bin/vim.nox
    when:    editor_realpath.stdout != '/usr/bin/vim.nox'
    tags:
        - vim

I guess I'd like the "set editor to vim" task to be "OK" if it is already set to vim, but it is showing up as "skipped".

Any thoughts?

-m

Richard Megginson

unread,
Sep 26, 2023, 8:39:46 PM9/26/23
to ansible...@googlegroups.com
On Tue, Sep 26, 2023 at 6:17 PM 'Matt Zagrabelny' via Ansible Project <ansible...@googlegroups.com> wrote:
Here are the two tasks:

-
    name:         get editor realpath
    shell:        realpath /usr/bin/editor

Use `command` here instead of `shell`
 
    register:     editor_realpath
    changed_when: False
    tags:
        - vim

-
    name:    set editor to vim
    command: update-alternatives --set editor /usr/bin/vim.nox
    when:    editor_realpath.stdout != '/usr/bin/vim.nox'
    tags:
        - vim

I guess I'd like the "set editor to vim" task to be "OK" if it is already set to vim, but it is showing up as "skipped".

Not sure how to do that
 

Matt Zagrabelny

unread,
Sep 26, 2023, 9:18:07 PM9/26/23
to ansible...@googlegroups.com
On Tue, Sep 26, 2023 at 7:39 PM Richard Megginson <rmeg...@redhat.com> wrote:


On Tue, Sep 26, 2023 at 6:17 PM 'Matt Zagrabelny' via Ansible Project <ansible...@googlegroups.com> wrote:
Here are the two tasks:

-
    name:         get editor realpath
    shell:        realpath /usr/bin/editor

Use `command` here instead of `shell`

Sure thing.
 
 
    register:     editor_realpath
    changed_when: False
    tags:
        - vim

-
    name:    set editor to vim
    command: update-alternatives --set editor /usr/bin/vim.nox
    when:    editor_realpath.stdout != '/usr/bin/vim.nox'
    tags:
        - vim

I guess I'd like the "set editor to vim" task to be "OK" if it is already set to vim, but it is showing up as "skipped".

Not sure how to do that

Fair enough. You've been very helpful, Richard. Thanks again for all the help!

-m
Reply all
Reply to author
Forward
0 new messages