# register output of shell command

**URL:** <https://forum.ansible.com/t/register-output-of-shell-command/38072>\
**Category:** Ansible Project\
**Created:** [June 8, 2023, 10:35am UTC](https://forum.ansible.com/t/register-output-of-shell-command/38072 "2023-06-08T10:35:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kathy\_L](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kathy_l/32/2652_2.png) [@Kathy\_L](https://forum.ansible.com/u/Kathy_L)\
**Post date:** [June 8, 2023, 10:35am UTC](https://forum.ansible.com/t/register-output-of-shell-command/38072/1 "2023-06-08T10:35:41Z")

</div>

I have what I thought was an easy problem to solve. A client has several different set ups of Debian 10 hosts. We are using ansible to install osqueryd and need to install the osqueryd.service file. I am trying to register the first result of the command:

“locate osqueryd.service.”

The error I am getting is:  
“Invalid variable name is ‘register’ specified: 'osqueryd-service-file”

Here is my ansible code:

- name: Locate osqueryd.service file  
command: “locate osqueryd.service”  
register: osqueryd-service-file

- name: Print osqueryd.service file  
debug:  
msg: “osqueryd service file is osqueryd-service-file.results.1.stdout”

I don’t even get to the debug statement. Why won’t it let me register the results of the locate command?

---

<div class="post-metadata">

**Author:** ![mahespth](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mahespth/32/252_2.png) [@mahespth](https://forum.ansible.com/u/mahespth)\
**Post date:** [June 8, 2023, 10:46am UTC](https://forum.ansible.com/t/register-output-of-shell-command/38072/2 "2023-06-08T10:46:19Z")

</div>

Hi,

Try replacing the hyphens with underscores are per documentation below.

[https://docs.ansible.com/archive/ansible/2.4/playbooks\_variables.html#what-makes-a-valid-variable-name](https://docs.ansible.com/archive/ansible/2.4/playbooks_variables.html#what-makes-a-valid-variable-name)

Regards

---

<div class="post-metadata">

**Author:** ![Kathy\_L](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kathy_l/32/2652_2.png) [@Kathy\_L](https://forum.ansible.com/u/Kathy_L)\
**Post date:** [June 8, 2023, 11:04am UTC](https://forum.ansible.com/t/register-output-of-shell-command/38072/3 "2023-06-08T11:04:07Z")

</div>

Well, don’t I feel stupid about the hyphens. Thanks.

When I print out the results of the service file though, I get the following:

msg: “Osqueryd service file is /work/roles/wazuh/files/osqueryd.serice\n/usr/lib/systemd/system/osqueryd.service”

How do I get the results of the latter half - just /usr/lib/systemd/system/osqueryd.service?

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [June 8, 2023, 11:50am UTC](https://forum.ansible.com/t/register-output-of-shell-command/38072/4 "2023-06-08T11:50:46Z")

</div>

> Well, don’t I feel stupid about the hyphens. Thanks.
> 
> When I print out the results of the service file though, I get the following:
> 
> msg: “Osqueryd service file is /work/roles/wazuh/files/osqueryd.serice\n/usr/lib/systemd/system/osqueryd.service”
> 
> How do I get the results of the latter half - just /usr/lib/systemd/system/osqueryd.service?

According to your initial post you seem to construct that string yourself, using a variable.  
Don’t use msg in the debug task but just var.

In general parsing output of ‘locate’ seems fragile and I would consider that more archeology than configuration management…

---

<div class="post-metadata">

**Author:** ![Alex\_Wanderley](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/alex_wanderley/32/3232_2.png) [@Alex\_Wanderley](https://forum.ansible.com/u/Alex_Wanderley)\
**Post date:** [June 8, 2023, 2:41pm UTC](https://forum.ansible.com/t/register-output-of-shell-command/38072/5 "2023-06-08T14:41:59Z")

</div>

Hello,

Besides replacing the hyphens for underscore (as was already mentioned), aren’t you missing the {{}} in your msg statement?  
msg: “osqueryd service file is {{ osqueryd-service-file.results.1.stdout}}”

Alex
