To detect the current groupid (605) i am doing the following:
- action: command id -g mygroup
register: groupid
In $groupid then is the following then which is too much:
{uchanged: True, uend: u2012-08-14 11:09:45.162986, ustdout: u605,
ucmd: [uid, u-g, umygroup], urc: 0, module: command, ustart:
u2012-08-14 11:09:45.159758, ustderr: u, udelta: u0:00:00.003228}
If i want to reuse that variable then in another command you get an
error...i tried all the variants of brackets,
was it only intended for the only_if clause ?
- action: file path=/root/playbooks/test/$groupid state=directory
owner=$user group=$group
fatal: [10.101.1.123] => failed to parse: (k, v) = x.split("=")
ValueError: need more than 1 value to unpack
(latest devel on centos)
Works great now when used inside the playbook directly !
When i try to use this var inside a var-file which is used by a
template later on i get a syntax error during import.
Probably because of the brackets syntax or the "register" variable is
only defined later at runtine within the tasks part and not known
yet ?
ERROR: Syntax Error while loading YAML script, vars/myproduct.yml
...
ProcessUserID=${userid.stdout},
ProcessGroupID=${groupid.stdout},
...
vars_files is processed ahead of tasks in the playbook, so you can't
make reference to registered variables there.
I am overdue to write a quick writeup on variable precedence, but
think "inventory first, then top down". And since the task register
happens in vars_files, you can't reference it there.
(Further, vars_files is YAML is templated at all)
What you want to do is is just reference it in your config file
template instead, and just like Daniel shared.
If you need a better name, perhaps "register: FooProcessGroupId", to
leave it less ambiguous.