Registered variable returns expected value but task is skipped

62 views
Skip to first unread message

Lucas Possamai

unread,
Dec 9, 2021, 7:05:45 PM12/9/21
to ansible...@googlegroups.com
I'm trying to only run a task if the previous task returned a 0 stdout.

- name: Check if efs-utils is already installed
ansible.builtin.shell: dpkg -l | grep efs-utils | wc -l
register: is_installed
ignore_errors: "{{ ansible_check_mode }}"
when: efs_id != "" and not ansible_check_mode

- name: Debugging
ansible.builtin.debug:
msg:
- "{{ is_installed.stdout }}"

- name: Install efs-utils
ansible.builtin.shell: cd /opt/efs-utils && ./build-deb.sh && sudo apt-get -y install /opt/efs-utils/build/amazon-efs-utils*deb
when: is_installed.stdout == 0 and not ansible_check_mode


However, when executing the playbook, the "Install efs-utils" task is being skipped.

Debug shows the "is_installed.stdout" output returning 0, as expected:
TASK [Check if efs-utils is already installed] ********************************************************************************
changed: [localhost]

TASK [Debugging] **************************************************************************************************************
ok: [localhost] => {
    "msg": [
        "0"
    ]
}

TASK [debug] ******************************************************************************************************************
ok: [localhost] => {
    "is_installed": {
        "changed": true,
        "cmd": "dpkg -l | grep efs-utils | wc -l",
        "delta": "0:00:00.013971",
        "end": "2021-12-09 23:58:31.128076",
        "failed": false,
        "msg": "",
        "rc": 0,
        "start": "2021-12-09 23:58:31.114105",
        "stderr": "",
        "stderr_lines": [],
        "stdout": "0",
        "stdout_lines": [
            "0"
        ]
    }
}

TASK [Install efs-utils] ******************************************************************************************************
skipping: [localhost]


What am I missing here?

Ansible version 2.11.6

Dick Visser

unread,
Dec 10, 2021, 3:17:51 AM12/10/21
to ansible...@googlegroups.com
The output is a string "0" but your condition uses a bare 0 which is interpreted as a Boolean false.

But why use a shell workaround, if there is package_facts:

Ideally AWS would provide apt repositories but that's not the case (yet - I see it's been requested, for instance 



--
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/CAE_gQfVO%3DCDER0KLREJ2zevRB45VmvbCkS21AtFAC5zotr4uNw%40mail.gmail.com.
--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.
Reply all
Reply to author
Forward
0 new messages