The expression you want is

    echo '{{ servers[SERVERS].url }}'

But beware: Ansible variable names are supposed to be all lower-case. The 
above should work with "SERVERS" for now, but it's frowned upon.

On Tuesday, December 6, 2022 at 11:38:29 AM UTC-5 [email protected] wrote:

> Hi, I need your help, this is my stage.
>
> Good morning I need your help, I want to run a playbook using a console 
> variable and compare it with a dictionary, example:
>
> ansible-playbook --extra-vars "SERVER=new" example. <https://example.com/>
> yaml
>
> If in the console variable I type new I want to print the value of the url 
> key belonging to new and if I type old I type the url value in old.
>
> ---
> - name: "Instalando Elastic Logger"
>   hosts: localhost
>   gather_facts: no
>   vars:
>    servers:
>       new: 
>         url: "url-new"
>       old: 
>         url: "url-old"
>   tasks:
>     - name: "Debug"
>       shell: echo '{{ url-new }} '
>       when: new in dict
>
>     - name: "Debug"
>       shell: echo '{{ url-old }} '
>       when: old in dict
>
> any helps?
>
> Regards,
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/34898ef4-0875-4b9e-bf19-24b58c2d639en%40googlegroups.com.

Reply via email to