FreeKB - ansible-playbook command - invoking a shell command
ansible-playbook command - invoking a shell command

Home > Search


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

In your playbook.yml file, the "shell" option can be used to run a shell command on the target servers. In this example, the ps command will be invoked on the Linux target servers.

- name: ps command
  shell: "ps"

 

The playbook can then be executed using this command.

ansible-playbook playbook.yml -i inventory.yml

 

The following should be produced.

PLAY [all]

TASK [Gathering Facts]
ok: [server1.example.com]

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

PLAY RECAP
server1.example.com : ok=2  changed=1  unreacable=0  failed=0

 

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

 


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 2daf2 in the box below so that we can be sure you are a human.




Comments