# Conditional role

**URL:** <https://forum.ansible.com/t/conditional-role/27846>\
**Category:** Ansible Project\
**Created:** [June 22, 2018, 1:02am UTC](https://forum.ansible.com/t/conditional-role/27846 "2018-06-22T01:02:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rob\_Christian](https://avatars.discourse-cdn.com/v4/letter/r/57b2e6/32.png) [@Rob\_Christian](https://forum.ansible.com/u/Rob_Christian)\
**Post date:** [June 22, 2018, 1:02am UTC](https://forum.ansible.com/t/conditional-role/27846/1 "2018-06-22T01:02:15Z")

</div>

I’m trying to modify this Ansible project and learn as I go. The role shown below is throwing errors and I’d like to clean those up, as well as make it optional. Everything in this role is concerned with installing Python and running tests, something that I don’t care about right now because I’m deploying on VM’s.

`

- name: Bootstrap coreos hosts  
hosts: all  
gather\_facts: false  
roles:
- role: bootstrap/ansible-bootstrap  
tags: [ansible-bootstrap]

`

But I can’t get anything to work. If I comment it out, I get errors. If I put an override on every test, causing it to return 0 tests, I get errors. I don’t know what to do.

---

<div class="post-metadata">

**Author:** ![Rob\_Christian](https://avatars.discourse-cdn.com/v4/letter/r/57b2e6/32.png) [@Rob\_Christian](https://forum.ansible.com/u/Rob_Christian)\
**Post date:** [June 22, 2018, 1:20am UTC](https://forum.ansible.com/t/conditional-role/27846/2 "2018-06-22T01:20:01Z")

</div>

I meant to say “tasks”, not “tests”. The role file is just a list of tasks.

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [June 22, 2018, 1:49am UTC](https://forum.ansible.com/t/conditional-role/27846/3 "2018-06-22T01:49:01Z")

</div>

You need to tell us what errors you are getting. Ideally, post the role code as well.

“Doctor, it hurts!” is not enough to diagnose you 🙂

Regards, K.

---

<div class="post-metadata">

**Author:** ![Rob\_Christian](https://avatars.discourse-cdn.com/v4/letter/r/57b2e6/32.png) [@Rob\_Christian](https://forum.ansible.com/u/Rob_Christian)\
**Post date:** [June 22, 2018, 2:31am UTC](https://forum.ansible.com/t/conditional-role/27846/4 "2018-06-22T02:31:25Z")

</div>

Hi Karl, sure thing.

So I think I have the conditional working for the role, but not I’m stuck on testing that a directory exists. Here is the role.

`

# filename: roles/bootstrap/ansible-bootstrap/tasks/configure.yml

- block:
- name: Check if Python is installed  
raw: “[-e {{ ansible\_python\_interpreter }}] && echo ‘yes’ || echo ‘no’”  
register: python\_install  
when: false

# changed\_when: false

- name: Check if install tar file exists  
raw: “[-e /tmp/pypy-{{ pypy\_version }}.tar.bz2] && echo ‘/tmp/pypy-{{ pypy\_version }}.tar.bz2’ || echo ""”  
register: pypy\_tar\_file  
when: false

- name: Check if pypy directory exists  
raw: “[-e {{ pypy\_dir }}] && echo ‘{{ pypy\_dir }}’ || echo ""”  
register: pypy\_directory  
when: false

- name: Check if libtinfo is simlinked  
raw: “[-e {{ pypy\_dir }}/lib/libtinfo.so.5] && echo ‘{{ pypy\_dir }}/lib/libtinfo.so.5’ || echo ""”  
register: libtinfo\_symlink  
when: false  
ignore\_errors: yes

- name: Download PyPy  
raw: wget -O /tmp/pypy-{{ pypy\_version }}.tar.bz2 [https://bitbucket.org/pypy/pypy/downloads/pypy-](https://bitbucket.org/pypy/pypy/downloads/pypy-){{ pypy\_version }}-linux64.tar.bz2  
when: pypy\_tar\_file.stdout == “”

- name: Extract PyPy  
raw: mkdir -p {{ pypy\_dir }} && tar xf /tmp/pypy-{{ pypy\_version }}.tar.bz2 -C {{ pypy\_dir }}/ --strip-components=1  
args:  
warn: false  
when: pypy\_directory.stdout == “”

- name: Symlink libncurses as libtinfo.so.5  
raw: mkdir -p {{ pypy\_dir }}/lib && ln -s /lib64/libncurses.so.5.9 {{ pypy\_dir }}/lib/libtinfo.so.5  
args:  
warn: false  
when: libtinfo\_symlink.stdout == “”

- name: Install PyPy  
script: bootstrap.sh {{ pypy\_dir }} {{ ansible\_python\_interpreter }}  
when: python\_install.stdout == ‘yes’

`

The error message seems to implicate the `ansible_python_interpreter` variable, since it has the path `/home/core/bin/python`.

I’ve also tried this popular variation:

`

- name: Check if Python is installed  
stat:  
path: ansible\_python\_interpreter  
register: python\_install  
when: false

`

And updated the when at the bottom. Also tried using `- debug`.

`

```auto
when: file_details.stat.exists

```

`

No matter what I do, the output is always the same, which leads me to conclude the error must be somewhere else, but I can’t see where else it could be coming from. Is it because everything above it was skipped?

`

Bringing machine ‘etcd-01’ up with ‘virtualbox’ provider…

Bringing machine ‘kube-master-01’ up with ‘virtualbox’ provider…

Bringing machine ‘kube-worker-01’ up with ‘virtualbox’ provider…

Bringing machine ‘kube-worker-02’ up with ‘virtualbox’ provider…

**==\> etcd-01: Checking if box ‘coreos-stable’ is up to date…**

**==\> etcd-01: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines…**

**==\> etcd-01: Machine already provisioned. Run `vagrant provision` or use the `--provision`**

**==\> etcd-01: flag to force provisioning. Provisioners marked to run always will still run.**

**==\> kube-master-01: Checking if box ‘coreos-stable’ is up to date…**

**==\> kube-master-01: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines…**

**==\> kube-master-01: Machine already provisioned. Run `vagrant provision` or use the `--provision`**

**==\> kube-master-01: flag to force provisioning. Provisioners marked to run always will still run.**

**==\> kube-worker-01: Checking if box ‘coreos-stable’ is up to date…**

**==\> kube-worker-01: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines…**

**==\> kube-worker-01: Machine already provisioned. Run `vagrant provision` or use the `--provision`**

**==\> kube-worker-01: flag to force provisioning. Provisioners marked to run always will still run.**

**==\> kube-worker-02: Checking if box ‘coreos-stable’ is up to date…**

**==\> kube-worker-02: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines…**

**==\> kube-worker-02: Machine already provisioned. Run `vagrant provision` or use the `--provision`**

**==\> kube-worker-02: flag to force provisioning. Provisioners marked to run always will still run.**

PLAY [Bootstrap coreos hosts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [bootstrap/ansible-bootstrap : Check if Python is installed] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

skipping: [kube-master-01]

skipping: [etcd-01]

skipping: [kube-worker-01]

skipping: [kube-worker-02]

TASK [bootstrap/ansible-bootstrap : Check if install tar file exists] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

skipping: [kube-master-01]

skipping: [etcd-01]

skipping: [kube-worker-01]

skipping: [kube-worker-02]

TASK [bootstrap/ansible-bootstrap : Check if pypy directory exists] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

skipping: [kube-master-01]

skipping: [etcd-01]

skipping: [kube-worker-01]

skipping: [kube-worker-02]

TASK [bootstrap/ansible-bootstrap : Check if libtinfo is simlinked] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

skipping: [kube-master-01]

skipping: [etcd-01]

skipping: [kube-worker-01]

skipping: [kube-worker-02]

TASK [bootstrap/ansible-bootstrap : Download PyPy] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

skipping: [kube-master-01]

skipping: [etcd-01]

skipping: [kube-worker-01]

skipping: [kube-worker-02]

TASK [bootstrap/ansible-bootstrap : Extract PyPy] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

skipping: [kube-master-01]

skipping: [etcd-01]

skipping: [kube-worker-01]

skipping: [kube-worker-02]

TASK [bootstrap/ansible-bootstrap : Symlink libncurses as libtinfo.so.5] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

skipping: [kube-master-01]

skipping: [etcd-01]

skipping: [kube-worker-01]

skipping: [kube-worker-02]

TASK [bootstrap/ansible-bootstrap : Install PyPy] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

skipping: [kube-master-01]

skipping: [etcd-01]

skipping: [kube-worker-01]

skipping: [kube-worker-02]

TASK [bootstrap/ansible-bootstrap : Test if Python is installed] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

skipping: [kube-master-01]

skipping: [etcd-01]

skipping: [kube-worker-01]

skipping: [kube-worker-02]

TASK [bootstrap/ansible-bootstrap : Gather ansible facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

skipping: [kube-master-01]

skipping: [etcd-01]

skipping: [kube-worker-01]

skipping: [kube-worker-02]

PLAY [Create certificates for Kubernetes componentes] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [Gathering Facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

fatal: [etcd-01]: FAILED! =\> {“changed”: false, “module\_stderr”: “Connection to 127.0.0.1 closed.\r\n”, “module\_stdout”: “/bin/sh: /home/core/bin/python: No such file or directory\r\n”, “msg”: “MODULE FAILURE”, “rc”: 127}

fatal: [kube-worker-01]: FAILED! =\> {“changed”: false, “module\_stderr”: “Connection to 127.0.0.1 closed.\r\n”, “module\_stdout”: “/bin/sh: /home/core/bin/python: No such file or directory\r\n”, “msg”: “MODULE FAILURE”, “rc”: 127}

fatal: [kube-master-01]: FAILED! =\> {“changed”: false, “module\_stderr”: “Connection to 127.0.0.1 closed.\r\n”, “module\_stdout”: “/bin/sh: /home/core/bin/python: No such file or directory\r\n”, “msg”: “MODULE FAILURE”, “rc”: 127}

fatal: [kube-worker-02]: FAILED! =\> {“changed”: false, “module\_stderr”: “Connection to 127.0.0.1 closed.\r\n”, “module\_stdout”: “/bin/sh: /home/core/bin/python: No such file or directory\r\n”, “msg”: “MODULE FAILURE”, “rc”: 127}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

etcd-01 : ok=0 changed=0 unreachable=0 failed=1

kube-master-01 : ok=0 changed=0 unreachable=0 failed=1

kube-worker-01 : ok=0 changed=0 unreachable=0 failed=1

kube-worker-02 : ok=0 changed=0 unreachable=0 failed=1

`

This is the repo I’ve been working from: [GitHub - sebiwi/kubernetes-coreos: Automatic local Kubernetes cluster provisioning and configuration on CoreOS using Ansible and Vagrant](https://github.com/sebiwi/kubernetes-coreos)

Starts with the Makefile, then enters kubernetes.yml, and the subject of concern is the very first role listed.
