On Thu, Mar 12, 2015 at 10:20 AM, Rick Kasten <[email protected]> wrote:
> These answers don't make sense to me. Here's what I've got:
>
> # inventory/dse/group_vars/dse/
> package_versions.yml
> package_versions:
>   app:
>     oraclejre_version: jdk1.7.0_75
>
> # roles/oraclejre/tasks/main.yml
> - name: OracleJRE | Make OracleJRE {{ version }} home directory
>   file: path=/usr/local/java-{{ version }} state=directory
>   sudo: yes
>
> # roles/oraclejre/vars/main.yml
> oraclejre_versions:
>   jdk1.7.0_75:
>     download_filename: jdk-7u75-linux-x64.tar.gz
>     download_url:
> "http://download.oracle.com/otn-pub/java/jdk/7u75-b13/jdk-7u75-linux-x64.tar.gz";
>
> # roles/app/meta/main.yml
> dependencies:
>   - { role: oraclejre, version: "{{ package_versions.app.oraclejre_version
> }}" }
>
> and my output looks like this:
>
> TASK: [oraclejre | OracleJRE | Make OracleJRE {{
> package_versions.app.oraclejre_version }} home directory] ***
> changed: [dse02] => {"changed": true, "gid": 0, "group": "root", "mode":
> "0755", "owner": "root", "path": "/usr/local/java-jdk1.7.0_75", "secontext":
> "unconfined_u:object_r:usr_t:s0", "size": 4096, "state": "directory", "uid":
> 0}
>
> Now it would seem to me that if everyone's explanations were correct that my
> task should have failed, because "{{ package_versions.app.oraclejre_version
> }}" should not resolve properly AT ALL for the reasons that everyone has
> stated. But you can see that it IS resolving properly :  "path":
> "/usr/local/java-jdk1.7.0_75". So why would it resolve properly in the file:
> field but not the name: field?
>
I'm not sure I see the reason you have for thinking it won't resolve at all...

In general the difference between the name field of a task resolving
and the same variable within a task is that the name field is
templated once per task whereas the parts that make up what is
executed in the task are templated once per host.  So something that
is at the host/group level can't be known at the time that we template
and print out the name field.  But it will be known by the time we
loop over the task body.

You could think of it sort of like this pseudo code:

global_vars = resolve_globals()
print (template(name_field, global_vars))
for host in hosts:
    host_and_group_vars = resolve_host_and_group(host)
    execute(template(task, global_vars, host_and_group_vars))


( Any of these specific cases could be because of the bug I linked to
later in the thread: https://github.com/ansible/ansible/issues/10347
but I can't guarantee it... there are certain variables that simply
aren't available at the time the name field is printed but are
available once we start looping over the task itself.)

-Toshio

-- 
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/CAG9juEpfrfrdfr-Q6m9UgYnVKywK4NpXqe7V6E25uywEJXDf8A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to