<p>You use pretty old ansible, maybe worth to try a new one. Although tests "succeeded" and "success" should be in 2.2 too.</p>

<p>But main problem I think it's <code>failed_when: no</code> in your task. It makes test <code>when: aptitude_installed is success</code> completely useless, it will be always <code>true</code> because <code>failed_when: no</code> marks all tasks as successful.</p>

<p>If you don't want to stop on task, but still to have an idea how it went, you should use <code>ignore_errors: true</code>, not <code>failed_when: no</code>. With <code>ignore_errors: true</code> you can both continue your playbook and inspect a real tasks results.</p>

CC BY-SA 4.0
2019-10-06T22:03:51.670Z
2019-10-06T22:03:51.670Z
DominiCane
<p>I got this error also and ended up here, reason is I think I was using another version of ansible on another computer so I changed the syntax to <code>when: sometest is success</code> because I got warnings before. Now on this computer where I run version <code>2.2.1.0</code> apparently this does not work at all, so I fell back on <code>when: sometest|success</code> instead and now it works.</p>

CC BY-SA 4.0
2019-10-27T14:34:18.837Z
2019-10-27T14:34:18.837Z
Gesias
<p>I do not have any clue of how your code once ran and produced the expected result. The <code>when</code> clause cannot be executed (as you found out from the error) and would anyway produce the reverse result you are expecting if I follow the underlying logic (install the package only when it is already installed). Moreover, your are in this simple case far from good ansible practice.</p>

<p>You should avoid using <code>shell</code> and <code>command</code> when there is an existing module that already does the job and manages idempotency for you. In present case, you can use the agnostic <a href="https://docs.ansible.com/ansible/latest/modules/package_module.html" rel="nofollow noreferrer"><code>package</code></a> module or the specific <a href="https://docs.ansible.com/ansible/latest/modules/apt_module.html" rel="nofollow noreferrer"><code>apt</code></a> (which I will prefer in my example since your playbook targets an Ubuntu install on wsl and a debian/ubuntu package anyway).</p>

<pre><code>tasks:
  - name: Ensure aptitude is installed
    apt:
      name: aptitude
      state: present
</code></pre>

<p>The above will simply install <code>aptitude</code> unless it is already there in a simple easy single task.</p>

CC BY-SA 4.0
2019-05-09T16:25:01.920Z
2019-05-09T16:25:01.920Z
Zeitounator
<p>I have an Ansible Playbook that is used to configure <a href="https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux" rel="nofollow noreferrer">WSL</a> on my Windows Laptop, having rebuilt my laptop recently I needed to run the playbook again, however it is failing with the following message:</p>

<pre><code>The conditional check 'aptitude_installed is success' failed. The error was: no test named 'success'
  line 1

The error appears to have been in '/mnt/c/source/richardslater/workstation-setup/wsl/plays/wsl.yml': line 15, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:

  - name: ensure aptitude is installed
    ^ here
</code></pre>

<p>The <a href="https://github.com/RichardSlater/workstation-setup/tree/master/wsl/plays" rel="nofollow noreferrer">context</a> from the playbook is:</p>

<pre><code>tasks:
- name: check if aptitude is installed
  shell: dpkg-query -W -f='${Status}' aptitude | grep 'install ok installed'
  register: aptitude_installed
  failed_when: no
  changed_when: no

- name: ensure aptitude is installed
  command: apt-get -y install aptitude warn=False
  when: aptitude_installed is success
</code></pre>

<p>The output of <code>dpkg-query -W -f='${Status}' aptitude | grep 'install ok installed'</code> is:</p>

<pre><code>install ok installed
</code></pre>

<p>and <code>ansible --version</code></p>

<pre><code>ansible 2.2.1.0
  config file = /mnt/c/source/richardslater/workstation-setup/wsl/plays/ansible.cfg
  configured module search path = Default w/o overrides
</code></pre>

<p>and <code>pip show jinja2</code></p>

<pre><code>Name: Jinja2
Version: 2.8
Summary: A small but fast and easy to use stand-alone template engine 
written in pure python.
Home-page: http://jinja.pocoo.org/
Author: Armin Ronacher
Author-email: armin.ronacher@active-4.com
License: BSD
Location: /usr/lib/python2.7/dist-packages
Requires: MarkupSafe
</code></pre>

<p>I'm not entirely sure how it ever worked, either that or something changed since I built this playbook, any ideas on how to fix?</p>

<ansible><jinja>
Ansible playbook fails with: no test named 'success'
Richard Slater
# Ansible playbook fails with: no test named 'success'

(Asked by: username_0 on 2019-05-09)

I have an Ansible Playbook that is used to configure WSL on my Windows Laptop, having rebuilt my laptop recently I needed to run the playbook again, however it is failing with the following message:
The conditional check 'aptitude_installed is success' failed. The error was: no test named 'success'
  line 1

The error appears to have been in '/mnt/c/source/richardslater/workstation-setup/wsl/plays/wsl.yml': line 15, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:

  - name: ensure aptitude is installed
    ^ here

The context from the playbook is:
tasks:
- name: check if aptitude is installed
  shell: dpkg-query -W -f='${Status}' aptitude | grep 'install ok installed'
  register: aptitude_installed
  failed_when: no
  changed_when: no

- name: ensure aptitude is installed
  command: apt-get -y install aptitude warn=False
  when: aptitude_installed is success

The output of dpkg-query -W -f='${Status}' aptitude | grep 'install ok installed' is:
install ok installed

and ansible --version
ansible 2.2.1.0
  config file = /mnt/c/source/richardslater/workstation-setup/wsl/plays/ansible.cfg
  configured module search path = Default w/o overrides

and pip show jinja2
Name: Jinja2
Version: 2.8
Summary: A small but fast and easy to use stand-alone template engine 
written in pure python.
Home-page: http://jinja.pocoo.org/
Author: Armin Ronacher
Author-email: armin.ronacher@active-4.com
License: BSD
Location: /usr/lib/python2.7/dist-packages
Requires: MarkupSafe

I'm not entirely sure how it ever worked, either that or something changed since I built this playbook, any ideas on how to fix?

**Tags:** ansible, jinja


---

## 3 answers

### Answer by username_1 on 2019-10-06. Score: 1

You use pretty old ansible, maybe worth to try a new one. Although tests "succeeded" and "success" should be in 2.2 too.

But main problem I think it's `failed_when: no` in your task. It makes test `when: aptitude_installed is success` completely useless, it will be always `true` because `failed_when: no` marks all tasks as successful.

If you don't want to stop on task, but still to have an idea how it went, you should use `ignore_errors: true`, not `failed_when: no`. With `ignore_errors: true` you can both continue your playbook and inspect a real tasks results.


---

### Answer by username_2 on 2019-10-27. Score: 0

I got this error also and ended up here, reason is I think I was using another version of ansible on another computer so I changed the syntax to `when: sometest is success` because I got warnings before. Now on this computer where I run version `2.2.1.0` apparently this does not work at all, so I fell back on `when: sometest|success` instead and now it works.


---

### Answer by username_3 on 2019-05-09. Score: 0

I do not have any clue of how your code once ran and produced the expected result. The when clause cannot be executed (as you found out from the error) and would anyway produce the reverse result you are expecting if I follow the underlying logic (install the package only when it is already installed). Moreover, your are in this simple case far from good ansible practice.
You should avoid using shell and command when there is an existing module that already does the job and manages idempotency for you. In present case, you can use the agnostic package module or the specific apt (which I will prefer in my example since your playbook targets an Ubuntu install on wsl and a debian/ubuntu package anyway).
tasks:
  - name: Ensure aptitude is installed
    apt:
      name: aptitude
      state: present

The above will simply install aptitude unless it is already there in a simple easy single task.


---

