# Ansible.utils.cli\_parse fails when command issues warning

**URL:** <https://forum.ansible.com/t/ansible-utils-cli-parse-fails-when-command-issues-warning/39939>\
**Category:** Get Help\
**Tags:** gcp\
**Created:** [January 31, 2025, 8:47am UTC](https://forum.ansible.com/t/ansible-utils-cli-parse-fails-when-command-issues-warning/39939 "2025-01-31T08:47:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![iamroddo](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/iamroddo/32/321_2.png) [@iamroddo](https://forum.ansible.com/u/iamroddo)\
**Post date:** [January 31, 2025, 8:47am UTC](https://forum.ansible.com/t/ansible-utils-cli-parse-fails-when-command-issues-warning/39939/1 "2025-01-31T08:47:56Z")

</div>

The following task fails with the message `WARNING: This command is using service account impersonation.`. Even though the command runs with error. I suppose I could add `ignore_errors` to the task, but I would like the task to fail, if the command fails. Any ideas how to get the task to not fail when this warning is present while permitting it to fail, if the command fails?

```yaml
- name: 'Get all user managed GCP service account keys'
  ansible.utils.cli_parse:
    command: >
      gcloud iam service-accounts keys list
      --iam-account={{ service_account.name }}
      --format=json
      --filter="keyType=USER_MANAGED"
      --sort-by=~validAfterTime
    parser:
      name: ansible.utils.json
    set_fact: _current_sa_keys

```

---

<div class="post-metadata">

**Author:** ![matteoclc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/matteoclc/32/7020_2.png) [@matteoclc](https://forum.ansible.com/u/matteoclc)\
**Post date:** [January 31, 2025, 8:09pm UTC](https://forum.ansible.com/t/ansible-utils-cli-parse-fails-when-command-issues-warning/39939/2 "2025-01-31T20:09:12Z")

</div>

You have to play with failed\_when, thus defining the condition(s) to be considered a failure.

There are many examples in the documentation  
[https://docs.ansible.com/ansible/latest/playbook\_guide/playbooks\_error\_handling.html](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_error_handling.html)

Good luck!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [March 2, 2025, 8:09pm UTC](https://forum.ansible.com/t/ansible-utils-cli-parse-fails-when-command-issues-warning/39939/3 "2025-03-02T20:09:27Z")

</div>

Closed on March 2, 2025, 8:09pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
