I want to add one role in my playbook dependencies, but based on condition.
- name: Get all install pyenv versions
command: '{{ pyenv_root }}bin/pyenv versions'
register: available_versions
tags:
- get_pyenv_versions
environment:
PYENV_ROOT: "{{ pyenv_root }}"
dependencies:
- { role: pyenv, python_versions: ["{{ mypython_version }}"], when: "mypython_version not in available_versions.stdout" }
What I want to do is, I want to check, all available pyenv
versions, if mypython_version
is not available, then only I want to invoke pyenv
role, otherwise I dont want to invoke that.
It gives me syntax error
ERROR! Syntax Error while loading YAML.
The error appears to have been in '/root/ansible_playbooks/roles/mydeployment/meta/main.yaml': line 9, column 1, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
dependencies:
^ here
exception type: <class 'yaml.parser.ParserError'>
exception: while parsing a block collection
in "<unicode string>", line 1, column 1
did not find expected '-' indicator
in "<unicode string>", line 9, column 1
How can I define variable get_pyenv_versions
and use in my dependencies
as condition?