gmaurice@linkfluence.net wrote:
Hello everybody,
I'm running ansible version 0.9, and i would like to pass a hash as an
argument of an include.
devel should have part of this fixed, where it will resolve ${x.foo} even
though $x is just '$y' but ${y.foo} exists.
I'm trying to do that in the top level playbook :
- hosts: $hosts
vars_files:
- projects/$project/$level.yml
tasks:
- include: tasks/elasticsearch.yml elasticsearch=$hash_elasticsearch
Note, hash_elasticsearch isn't defined below.
$project and $level are get from group_vars, and no problem to get vars
from the file.
The vars_file used is projects/proj1/prod.yml that is look like :
main_elasticsearch:
version: 0.19.11-1
cluster_name: main_app
specific_elasticsearch:
version: 0.19.11-2
cluster_name: specific_app
The included playbook looks like :
---
- name: Install Elasticsearch
tags: install
action: apt pkg=elasticsearch=$elasticsearch.version update-cache=yes
To access sub-variables you need ${elasticsearch.version}.
And i have the following error :
TASK: [Install Elasticsearch] *********************
failed: [****.***.**] => {"failed": true, "item": ""}
msg: 'apt-get install 'elasticsearch=$elasticsearch.version' ' failed: E:
Version '$hash_elasticsearch.version" for elasticsearch' was not found
This form does not work too :
---
- name: Install Elasticsearch
tags: install
action: apt pkg=elasticsearch=${$elasticsearch.version} update-cache=yes
This is a different thing entirely, attempting to access a variable by the
name of whatever is in $elasticsearch (in this case '$hash_elasticsearch'),
and then version within that.
Is it possible to do that ?
I'm not entirely sure what it is that you want to do. You can use variables.
You can use variables within variables. Variables can refer to eachother.
If you tell us what is that you want, and how you are telling ansible to do
it, we might be of more help.
Daniel