If I remember correctly, it does not work, when you define a variable and 
try to use it in same "block" in this case vars:

Both mysql_os and mysql_el6_base are defined in vars, so when expanding 
mysql_el6_base the mysql_os is not yet defined.

And the solution I used was to separate them into multiple vars_files.

On Wednesday, October 18, 2017 at 7:28:42 PM UTC+2, eray wrote:
>
> I am not sure if its my misuse of jinja within ansible, but I am seeing 
> strange behavior from what would seem to be a typical use case for managing 
> dynamic variables. As you can see from the code below, I am using the 
> mysql_os variable to determine the list to select items from.  This may be 
> the intended behavior, but I swear I have done this in the past.  I tested 
> on 2.3, and 2.2 with the same results.
>
> ---
>   - hosts: localhost
>     connection: local
>     vars:
>       mysql_os: "el6"
>
>       mysql_el6_base:
>         - "MySQL-server-{{ mysql_os }}"
>
>       mysql_el7_base:
>         - "mysql-community-server-{{ mysql_os }}"
>     tasks:
>       - debug: msg="{{ item }}.x86_64.rpm"
>         with_items:
>           - "{{vars['mysql_' + mysql_os + '_base']}}"
>
> Expected Result
> TASK [debug] 
> ******************************************************************************************************************
> ******
> ok: [localhost] => (item=MySQL-server-el6) => {
>     "item": "MySQL-server-el6",
>     "msg": "MySQL-server-el6.x86_64.rpm"
> }
>
>
>
> Actual Result
> TASK [debug] 
> ******************************************************************************************************************
> ******
> ok: [localhost] => (item=MySQL-server-{{ mysql_os }}) => {
>     "item": "MySQL-server-{{ mysql_os }}",
>     "msg": "MySQL-server-{{ mysql_os }}.x86_64.rpm"
> }
>
>
> Thanks
>
>

-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/9315fc69-67ab-451b-a1b2-ecb92fa8178d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to