register output of shell command

38 views
Skip to first unread message

Kathy L

unread,
Jun 8, 2023, 6:35:41 AM6/8/23
to Ansible Project
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?

Stephen Maher

unread,
Jun 8, 2023, 6:46:35 AM6/8/23
to ansible...@googlegroups.com
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

Regards



--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/71d6a619-8e30-44e9-b18f-4557f3fc7387n%40googlegroups.com.

Kathy L

unread,
Jun 8, 2023, 7:04:07 AM6/8/23
to Ansible Project
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?

Dick Visser

unread,
Jun 8, 2023, 7:51:16 AM6/8/23
to ansible...@googlegroups.com
On Thu, 8 Jun 2023 at 13:04, Kathy L <lyon...@gmail.com> wrote:
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...


--
Sent from Gmail Mobile

Alex Wanderley

unread,
Jun 8, 2023, 10:42:33 AM6/8/23
to ansible...@googlegroups.com
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

--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/71d6a619-8e30-44e9-b18f-4557f3fc7387n%40googlegroups.com.


--

 

Edmonton_sig_RGB_S.jpg

Alex Wanderley

Application and Infrastructure Analyst II
Acting Team Lead Server Solutions & Automation

Financial and Corporate Services | Open City and Technology  

 

780-496-4156  Office

780-819-0273  Mobile

 

City of Edmonton

Century Place, 19th Floor

9803 102A Avenue NW

Edmonton AB, T5J 3A3

 

All information contained in this email post is proprietary to the City of Edmonton, confidential and intended only for the addressed recipient. If you have received this post in error, please disregard the contents, inform the sender of the misdirection, and remove it from your system. The copying, dissemination or distribution of this email, if misdirected, is strictly prohibited.


The contents of this message and any attachment(s) are confidential, proprietary to the City of Edmonton, and are intended only for the addressed recipient. If you have received this in error, please disregard the contents, inform the sender of the misdirection, and remove it from your system. The copying, dissemination, or distribution of this message, if misdirected, is strictly prohibited.
Reply all
Reply to author
Forward
0 new messages