Ansible Command Module Argument Entry

45 views
Skip to first unread message

Carlton Patterson

unread,
May 19, 2018, 1:10:43 PM5/19/18
to Ansible Project
I'm trying to use Ansible's 'command' module to to issue the command 'hostname -s' on a machine. 

Can someone please take a look at the module and its arguments and let me know where I would enter the argument 'hostname -s'?




Karl Auer

unread,
May 19, 2018, 1:25:44 PM5/19/18
to ansible...@googlegroups.com
This runs your command on localhost:

---
# Test where vars are located
- hosts: localhost

  tasks:
    - name: run hostname command
      command: hostname -s


If you substitute the appropriate "hosts:" value , it will run it on another machine.

Regards, K.


--
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-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/4bb2a137-fbf3-4721-8531-d00835929b4f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Karl Auer

Email  : ka...@2pisoftware.com
Website: 
http://2pisoftware.com

GPG/PGP : 958A 2647 6C44 D376 3D63 86A5 FFB2 20BC 0257 5816
Previous: F0AB 6C70 A49D 1927 6E05 81E7 AD95 268F 2AB6 40EA

Jean-Yves LENHOF

unread,
May 19, 2018, 1:37:22 PM5/19/18
to ansible...@googlegroups.com

Hi,

Why using command to have the hostname ? (command and shell module should be avoided each time it is possible) Fact already have some variable you can use, no ?

Example on my personnal machine :

       "ansible_fqdn": "DellJylenhof",
        "ansible_hostname": "DellJylenhof",
        "ansible_nodename": "DellJylenhof",

As I have not parameter domain on my machine, regarding documentation what you want is "ansible_hostname"

Regards,

JYL
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CA%2B%2BT08TtTdwSmU8HohXz6RYBCpWXG1U%2BhBQm%3D_ZiUti%3DrHr%3DqQ%40mail.gmail.com.

Jordan Borean

unread,
May 19, 2018, 6:40:41 PM5/19/18
to Ansible Project
While yes running hostname as a command seems redundant in this example (if you gather facts). If you do want to run a command anyway you want to put it in the free form box. The command/shell/script/raw are some of the only modules that use this form.
Reply all
Reply to author
Forward
0 new messages