V
V
Vadim2019-06-09 00:13:02
Ansible
Vadim, 2019-06-09 00:13:02

How to execute task by default, adjusting with a (not) set variable?

Good afternoon everyone!
I want to pass a variable to the ansible playbook, for example ansible-playbook -e "myvar=true" myplaybook.yml
in the playbook there are task1 and task2 tasks
how to make it so that if the variable is not set, it will be considered false by default and task1 will be executed ( default)
and if it is set to true, then task2 was executed
thanks

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Shumov, 2019-06-09
@inoise

Jinja2 templates hasn't gone through yet?)

- name: Create user
  user:
    name: "{{ my_variable | default('default_value') }}"

P
Puma Thailand, 2019-06-09
@opium

In variables, define it as false by default

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question