FreeKB - shell module (invoking a shell command)
Ansible - shell module (invoking a shell command)

This assumes you have installed Ansible, are familiar with the ansible-playbook command and have created a playbook.

The shell module can be used to run a shell command on the target servers. In this example, the ps command will be invoked on the target servers.

- name: ps command
  shell: "ps"

 

The following should be produced.

TASK [ps command]
changed: [server1.example.com]

 

By default, no stdout is printed. The register module can be used to print output to the console.


non-zero return code

If non-zero return code is being displayed in the output of the play, refer to our article on resolving non-zero return code.

 


Sudo / Become

If you want to perform a task on target server(s) that requires the use of sudo, refer to our article on using the become module.

 


Arguments

Certain arguments can be used with the shell command. In this example, the chdir (change directory) argument is used to perform the shell command from a particular directory.

- name: ps command
  shell: "ls"
  arg:
    chdir: /root

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter 1bf9f in the box below so that we can be sure you are a human.




Comments