Ansible Shell

The shell module in Ansible is intended to run the shell orders against the objective UNIX based hosts. It can execute aside from any advanced block commands with the help of pipes, redirection. What’s more, you can likewise play out the shell contents utilizing the Ansible shell module.

The favorable fundamental position of the Ansible shell is with the exception of any high buildings orders with lines and semicolons, can be an impediment from the security point of view as a solitary error could cost a great deal and break the framework trustworthiness.

  • The shell module is intended to operate just on LINUX based machines and not on the windows. For windows, utilize the win_shell
  • Ansible shell module can be utilized to execute shell contents. Ansible has a committed module named content, which is utilized to duplicate the shell content from the control machine to the far-off worker.

Now we will check the syntax of how the Ansible shell module for its utilization in the playbook and Ad-hoc:

Syntax of Ansible shell module in a playbook

The manner in which an Ansible playbook looks and composed represents its magnificence. A playbook is written in YAML, so it very nicely may be efficiently comprehended.

The beneath picture exhibits the way an Ad-hoc order would be changed as a play playbook.

Ansible Shell

The syntax of an Ansible shell module in Ad-hoc is given below:

The underneath picture represents the fast syntax of the shell module in an Ad-hoc way.

Ansible Shell


chdirDefault: nonealbum into this registry before running the order
createsDefault: nonea filename, when it as of now exists, this progression won’t be run.
executableDefault: noneTransform the shell utilized to run the order. Ought to be a flat-out way to the executable.
free_form (necessary)Default: noneThe shell module receives a free form command to execute as a string or line. There’s not a real alternative named “free form.” Check out the examples!
removesDefault: nonea filename, when it doesn’t exist, this progression won’t be run.
stdin (included in 2.4)Default: noneSet the stdin of the order straightforwardly to the predetermined worth.
warn (included in 1.8)Default: yesif order alerts are on in ansible.cfg, don’t caution about this specific line whenever set to no/false.


Return Values

 Normal return values are reported here. Coming up next are the fields extraordinary to this module:

cmd (string)alwaysThe order executed by the errand.   Test:   rabbitmqctl join_cluster rabbit@master  
delta (string)alwaysThe order execution delta time   Test:   0:00:00.395641  
end (string)alwaysThe order execution end time   Test:   2018-12-05 06:58:36.754339  
msg (Boolean)alwayschanged   Test:   Valid  
rc (int)always  The order return code (0 means achievement)  
start (string)alwaysThe order execution start time   Test:   2018-12-05 06:58:46.420068  
stderr (string)alwaysThe order norm blunder   Test:   ls: can’t get to foo: No such document or directory  
stdout (string)always  The order standard yield   Test:   Clustering node rabbit@slave1 with rabbit@master …  
stdout_lines (list)alwaysThe order norm yield divided in lines   Test:   [“u’Clustering node rabbit@slave1 with rabbit@master …'”]


This module is hailed as stableinterface, which implies that the maintainers for this module ensure that no regressive contradictory interface changes will be made.

Pin It on Pinterest

Share This