# 777 register

**URL:** <https://forum.ansible.com/t/777-register/11796>\
**Category:** Ansible Project\
**Created:** [August 14, 2012, 9:39am UTC](https://forum.ansible.com/t/777-register/11796 "2012-08-14T09:39:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ansibleguest](https://avatars.discourse-cdn.com/v4/letter/a/b4bc9f/32.png) [@ansibleguest](https://forum.ansible.com/u/ansibleguest)\
**Post date:** [August 14, 2012, 9:39am UTC](https://forum.ansible.com/t/777-register/11796/1 "2012-08-14T09:39:47Z")

</div>

To detect the current groupid (605) i am doing the following:

- action: command id -g mygroup  
&nbsp;&nbsp;&nbsp;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)

---

<div class="post-metadata">

**Author:** ![Daniel\_Hokka\_Zakriss](https://avatars.discourse-cdn.com/v4/letter/d/f05b48/32.png) [@Daniel\_Hokka\_Zakriss](https://forum.ansible.com/u/Daniel_Hokka_Zakriss)\
**Post date:** [August 14, 2012, 11:05am UTC](https://forum.ansible.com/t/777-register/11796/2 "2012-08-14T11:05:28Z")

</div>

ansibleguest wrote:

> To detect the current groupid (605) i am doing the following:
> 
> - action: command id -g mygroup  
> &nbsp;&nbsp;&nbsp;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

Use ${groupid.stdout}

---

<div class="post-metadata">

**Author:** ![ansibleguest](https://avatars.discourse-cdn.com/v4/letter/a/b4bc9f/32.png) [@ansibleguest](https://forum.ansible.com/u/ansibleguest)\
**Post date:** [August 14, 2012, 12:03pm UTC](https://forum.ansible.com/t/777-register/11796/3 "2012-08-14T12:03:03Z")

</div>

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},  
...

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [August 14, 2012, 12:12pm UTC](https://forum.ansible.com/t/777-register/11796/4 "2012-08-14T12:12:44Z")

</div>

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.
