On 1/23/20 3:22 PM, Yehuda Pinhas wrote:
> *Hi!*
> *I want to make the variable qos_policy set on conditional basis:*
> *
> *
> *If bandwidth_mb == '50'*
> *  then qos_policy == 'qos-nested-50'*
> *
> *
> *else*
> *  qos_policy == 'qos-nested-new-50'*
> *
> *
> *
> *
> *My code is this (not working):*
>   qos_policy: "{{ 'qos-nested-new-' + bandwidth_mb }}"
>   qos_policy: "{{ 'qos-nested-' + bandwidth_mb }}"
>     when:
>       - bandwidth_mb == "50"
> 
>   bandwidth_mb: "some number"

Hello Yehuda,

variables don't have a when condition, but you can try:

qos_policy: "{% if bandwidth_mb == "50" %}{{ 'qos-nested-' + bandwidth_mb }}{% 
else %}{{ 'qos-nested-new-' +
bandwidth_mb }}{% endif %}"

(untested, but that's the idea)

Regards
          Racke

> 
> 
> 
> *Error:*
> [ansible@Netauto-Dev new_branch]$ ansible-playbook 
> test_new_branch_playbook.yml PLAY [TEST5_TLV5]
> *************************************************************************************************************************
>  TASK
> [include_vars]
> ***********************************************************************************************************************
> ok: [R-TEST5-TLV5] TASK [include_role : new_branch]
> **********************************************************************************************************
>  ERROR! Syntax
> Error while loading YAML. did not find expected key The error appears to be in
> '/etc/ansible/roles/new_branch/tasks/configure_som_tlv5.yml': line 8, column 
> 7, but may be elsewhere in the file
> depending on the exact syntax problem. The offending line appears to be: - 
> qos_policy: "{{ 'qos-nested-' + bandwidth_mb
> }}" when: ^ here PLAY RECAP
> ********************************************************************************************************************************
> R-TEST5-TLV5 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 
> ignored=0
> 
> *What is the problem?*
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to
> ansible-project+unsubscr...@googlegroups.com 
> <mailto:ansible-project+unsubscr...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/353c9445-4a49-4222-b98b-8a9bdf6d939c%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/353c9445-4a49-4222-b98b-8a9bdf6d939c%40googlegroups.com?utm_medium=email&utm_source=footer>.


-- 
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/2747b937-f670-bb27-035e-97c5d07f1bd2%40linuxia.de.

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to