Ansible Shell Module Tutorial – Complete Beginner's Guide
The Ansible Shell Module allows you to run arbitrary commands on a remote host, just like you were logged into the shell. The Shell and Command modules are very similar, the major difference being that the shell module does not escape commands, allowing you to use shell operators like redirects (“greater than”, “less than”), pipe (“|”) and boolean operators (“&&”, “||”). This does mean that the Shell module is susceptible to command injection/shell injection, but this is easy enough to overcome by using the “quote” filter when using variables with the Shell module.
– 0:00 — Shell Module vs Command Module
– 3:39 — Basic Shell Module Usage (+ args, environment and loops)
– 5:15 — Preventing Shell Injection
ℹ️ READ THE IN-DEPTH TUTORIAL HERE == http://bit.ly/2CXMois
SETUP/EDITOR/IDE
✅ Visual Studio Code (https://code.visualstudio.com/)
✅ Ansible extension by Microsoft (http://bit.ly/2SdnqoK).
✅ SEE HOW I SET UP ANSIBLE == https://youtu.be/yiooWsMERaY
Thanks for watching and hope it’s entertaining/useful for you! Hit me up in the comments if you have any questions or feedback 💪.
Related & Channel
▶️ http://bit.ly/2VWid3D == Playlist of all Ansible videos
⭐️ http://bit.ly/2HavqCu == Subscribe to our YouTube Channel
Our Site & Socials
🌐 http://bit.ly/2shtKwZ == TopTechSkills.com
🐦 http://bit.ly/2RkgZkk == @TopTechSkills on Twitter
🐦 http://bit.ly/2AA19aN == @PercyGrunwald on Twitter
😃 http://bit.ly/2ACQgEW == @TopTechSkills on Facebook
🕹 http://bit.ly/2CWR3ST == @PercyGrunwald on Twitch
source
Leave us a comment Cancel reply
COMMON QUESTIONS
Categories
- Agile Coach
- ARTIFICIAL INTELLIGENCE
- Block chain
- Business Analyst BA
- DATA science
- Development
- Devops Automation
- Dotnet
- Education
- Free Job training and assistance
- Information
- Infrastructure automation
- Interview questions
- JAVA
- jobs
- Learn
- Machine learning
- Python Automation
- QA Automation
- RPA Automation
- SAP crm
- Scrum master Agile
- Skill
- UI Design
- Uncategorized
17 Comments
Rizwan Khan A
May 12, 2022 19:38 pmHi Percy , thanks for all of your videos. Clear explanation of all the concepts. It’s very easy so that layman can even do calkwalk. I have a scenario to install python3.7 on windows using ansible I tried using win_package and win_shell but not able to install. Please can I ask you do a video on the same
CartesianColours
May 12, 2022 19:38 pmTx. Saved some heartache and broken keyboards.
Isuru Rangana Rathnayake
May 12, 2022 19:38 pmthanks a lot
Thomas Smit
May 12, 2022 19:38 pmIn which case would shell injection be a practical attack vector? I.e.: in which case does an attacker have access to variables, but not to the playbook, or ssh keys?
ace
May 12, 2022 19:38 pmGot yourself a new sub from PH. Thanks for a very concise video
Jon POK
May 12, 2022 19:38 pmDo have to do some more steps executing powershel script? I have add in playbook
tasks:
– name: powercli script
script: 1.ps1
but is not working DO I have to do sth. ANd when You help me start this is it possible to save otput from script?
Juergen Schubert
May 12, 2022 19:38 pmGreat video! Thumb up. I just wonder if I also can use the shell module to login to a ssh session and hit ENTER with the task as the first thing I need to do is "accept a EULA".
Amanjot Singh
May 12, 2022 19:38 pmIs there any way to run a shell script for both two hosts from local machine? What exactly we need to do for this? I'm pretty much stuck in this. The only thing I got is to copy the script on the host then running it using the command. Please let me know if there is another way to run the shell script file on the host which is placed on my local machine. Thanks in advance.
Ambhoj Shukla
May 12, 2022 19:38 pmIs it possible to perform ldap client add or remove via ansible playbook in linux?
D1Ck3n
May 12, 2022 19:38 pmHi, thanks for the video!
i have a question: is it possible to define a environment like this?:
HOSTNAMEKT: "echo "$(dmidecode -s system-serial-number)" | tr '[:upper:]' '[:lower:]'"
i want to change the hostname of a new machine to his serial number.
@Imran@Nikhat@ki@kahaani
May 12, 2022 19:38 pmnice percy sir. thank you sir
nagaraju Nagari
May 12, 2022 19:38 pmThank you sir, very very effective and useful for me.
Kundan Singh
May 12, 2022 19:38 pmHow did you setup your visual studio for ansible
Venkatesh Reddy
May 12, 2022 19:38 pmHi Sir,
May i know where u r mentioning the hosts names.Because i see u are not passing any parameters in the command.
manish shrivas
May 12, 2022 19:38 pmHi Percy,
Nice tutorial. I want to delete files inside directory. Directory contains authchild1.2.4, authchild1.3.7 and I have one another directory which contains file authchild1. 6.9 I want to copy this file into previous folder which contains 2 files (authchild1.2.4 and authchild1. 3.7) but after copy I want to delete same file which contains text authchild*.
George Snow
May 12, 2022 19:38 pmWhat platform and editor are you using for your demos?
Keyboard Interrupt
May 12, 2022 19:38 pmHi I really like your video and Tutorial series, definitely going to recommend it to beginners!, in this one I especially liked you mentioning Shell injection as many people are not aware of security implications of not sanitizing your inputs ^^
One thing, that might be out of the Beginner Scope, what about idempotency?, and how to achieve it by using Error Handling (https://docs.ansible.com/ansible/latest/user_guide/playbooks_error_handling.html)
Don't just do `ignore_errors: True` though!!! 😉
Also Maybe you should point out that most simple shell scripts can be replaced by a hand full of Tasks using the correct modules, and that using the Command Modules like Raw, Command, Shell and so on, should be avoided when a suitable Module is available.
This is my personal preference though, and getting started by utilizing existing Shell scripts via `Command` and `Shell` and replacing them, as time goes by, with "real" Ansible is still a huge Step in the right direction 😉
Maybe a great Video Idea would be a Break down of an existing Shell based deployment Script, and breaking it down into Ansible Tasks 🙂