On 24.04.2019 21:02, John Simmons wrote:
> I want to add a var of testing to my playbook, and when that var is set to
> true i want var1 to be used but if its nor set to true, i want it to use
> var2. Is this possible?
>
> below is a non working example but I hope it illustrates what i want it to
> do.
> -----------------------------------------------------------------------------------
>
> - name: Check logs and report to slack
> hosts:
> become: yes
> remote_user: "{{ platform_user }}"
>
> * vars:*
> * testing: true*
>
> vars_files:
> - "../../vault/slack.yml"
>
> tasks:
>
> - name: check logs for step took
> shell: "some command"
> register: command_output
>
> - name: sucess notification message via Slack
> slack:
> token: *"{% if {{ testing }} == 'true' %}{{ slack_slacktesting }}{% else %}{{ slack_devops }}{% endif %}"*
You are already in template mode so you can't use {{ }} inside {% %}, so delete the {{ }} and it will work
{% if testing == 'true' %}{{ slack_slacktesting }}{% else %}{{ slack_devops }}{% endif %}
There are some shorter version you could use:
{{ slack_slacktesting if testing == 'true' else slack_devops }}
or
{{ (testing == 'true') | ternary(slack_slacktesting, slack_devops) }}
--
Kai Stian Olstad