Ansible Shell Module Tutorial - Complete Beginner's Guide

  Рет қаралды 24,450

Percy Grunwald from TopTechSkills

Percy Grunwald from TopTechSkills

Күн бұрын

Пікірлер: 45
@toptechskills
@toptechskills 5 ай бұрын
G'day everyone, if you're currently learning Ansible and want to see how all these modules fit together to build something useful, please consider checking out my course and letting me know what you think! It's currently in "early access" while I finish off the last chapter, and the first part of the course is free so you can try it out: learn.toptechskills.com/courses/productive-with-ansible. Thanks for all your support and happy coding!
@ac3buddy
@ac3buddy 3 жыл бұрын
Got yourself a new sub from PH. Thanks for a very concise video
@toptechskills
@toptechskills 3 жыл бұрын
Thank you ace 🙏
@juergenschubert3247
@juergenschubert3247 4 жыл бұрын
Great 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".
@toptechskills
@toptechskills 4 жыл бұрын
Hmm, I don't know if that would be possible, but usually if the command you're trying to run has a "quiet" or "no prompt" mode, it should be able to run without input. If you check the `--help` output for the command, it should have some information about whether it has a mode like this. What are you trying to do with `shell` in this case?
@azamamer
@azamamer 2 жыл бұрын
Hi Percy, Can we use the shell module to request a certificate for an application? somehow when I run the following - name: Request new certs shell: "/opt/OV/bin/ovcert -certreq", the client doesn't get any new cert from the server.
@toptechskills
@toptechskills Жыл бұрын
What's the output from the command? You can run `ansible-playbook` with the `-v` option to produce more verbose output, which will print the stdout/stderr from the command.
@rizwankhana312
@rizwankhana312 2 жыл бұрын
Hi 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
@toptechskills
@toptechskills 2 жыл бұрын
Hi Rizwan, thank you for your comment. What problem did you encounter when trying to install python3.7 on Windows using those packages? Is it that the commands won't work without Python being installed on the systems already? If so, you might be able to make use the `raw` module.
@nagarajunagari2266
@nagarajunagari2266 4 жыл бұрын
Thank you sir, very very effective and useful for me.
@toptechskills
@toptechskills 4 жыл бұрын
Thank you for your comment nagaraju Nagari, I'm very happy the video was useful for you
@D1Ck3n
@D1Ck3n 4 жыл бұрын
Hi, 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.
@toptechskills
@toptechskills 4 жыл бұрын
Hi D1Ck3n, from my understanding, the environment won't be executed, it will be simply be passed as a string. To do what you want to do, you'd need to capture the output from a shell command and then pass that in as the environment: ``` - name: Print the formatted serial number shell: "echo \"$(dmidecode -s system-serial-number)\" | tr '[:upper:]' '[:lower:]'" register: serial_number_result - name: Print the shell module output for debugging purposes debug: var: serial_number_result - name: Set the hostname to serial number hostname: name: "{{ serial_number_result.stdout }}" ``` Hope this helps, thanks for your comment.
@thomassmit9944
@thomassmit9944 3 жыл бұрын
In 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?
@toptechskills
@toptechskills 3 жыл бұрын
That's a good question actually, I haven't thought about that deeply before. It's a good point: if you have access to the variables on the control machine, you would most likely have access to the target machine via SSH (and most likely be a sudoer on the target machine), so shell injection would likely not gain you much. If you have access to the variables on the target machine (but don't have access to the control machine), you _may_ be able to do something with shell injection, since it may be that the user executing the commands from the control machine is more privileged than the user whose access was used to modify the variables. One example may be to allow the compromised user account to escalate privileges. A final example I can think of is if variables are dynamically set from the result of an API call, compromise of the API would potentially allow the attacker to gain access to the target machine.
@manish5494
@manish5494 5 жыл бұрын
Hi 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*.
@toptechskills
@toptechskills 5 жыл бұрын
Hi Manish, thanks for your comment. Based on the way you've described your problem, there are multiple ways of varying complexity to solve your problem. The simplest would be to copy the files you want to copy with the `copy` module and then use the `shell` or `command` module to delete the files with `rm`. The more complex way would be to use the `find` module to find all the files that match your fileglob `authchild*` in the specified directory, capture the output of the task with `register` then iterate over the variable to delete each file in the registered variable with the `file` module. Hope this helps, let me know if you need any more details.
@jonpok2151
@jonpok2151 4 жыл бұрын
Do 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?
@toptechskills
@toptechskills 3 жыл бұрын
You can run your playbook in "verbose" mode to get more details (add the `-v` argument to the command line call to `ansible-playbook`). To save the output of the script you need to use the `register` keyword, take a look at this example from the `shell` module to see how you can use the `register keyword: www.toptechskills.com/ansible-tutorials-courses/ansible-shell-module-tutorial-examples/#how-to-capture-shell-module-output-from-a-loop Hope that helps!
@ZunnuAli
@ZunnuAli 4 жыл бұрын
nice percy sir. thank you sir
@theamanjs
@theamanjs 4 жыл бұрын
Is 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.
@toptechskills
@toptechskills 4 жыл бұрын
Hi Amanjot Singh, if you're trying to execute a script on the control machine for each target, you can use the `delegate_to` argument: docs.ansible.com/ansible/latest/user_guide/playbooks_delegation.html#delegation. In this case, you can delegate to local host, and use the `inventory_hostname` variable to reference the target machine. Hope that helps, thanks for your comment.
@theamanjs
@theamanjs 4 жыл бұрын
@@toptechskills Hello Percy, Thanks for helping me out. Really appreciate that you spare time for everyone to help. I found the solution and wrote a blog on that here thejsdeveloper.wordpress.com Though it is not the best way. I'll checkout the link you gave. Again Thank you much for this video and help. God bless you fella ☺️
@anthonychurch1567
@anthonychurch1567 2 ай бұрын
@@toptechskills Thanks for this answer. I came to this video as the Ansible Docs for script module confused me by saying you shouldn't run a script but turn it into an Ansible module. Yes it may be useful to the community to publish my solution as a module for others to use but not yet. No idea if there's another reason.
@venkatesh9290
@venkatesh9290 4 жыл бұрын
Hi Sir, May i know where u r mentioning the hosts names.Because i see u are not passing any parameters in the command.
@toptechskills
@toptechskills 4 жыл бұрын
Hi Venkatesh Reddy, I configured the hosts in another video, you can see my setup here: kzbin.info/www/bejne/r5rSoIqpgqqFl7s Hope it's clear from that video. Thank you for your comment.
@ambhojshukla
@ambhojshukla 4 жыл бұрын
Is it possible to perform ldap client add or remove via ansible playbook in linux?
@toptechskills
@toptechskills 4 жыл бұрын
Hi Ambhoj Shukla, generally if you can accomplish your goal with shell commands, it will also be possible using the `shell` or `command` modules in Ansible. There are also LDAP modules for doing various LDAP tasks, maybe they will do what you need: docs.ansible.com/ansible/latest/modules/ldap_entry_module.html#ldap-entry-module. The Ansible docs are a good place to start to see if a module exists for a particular task. Using a dedicated module (as opposed to the general-purpose `shell` and `command` modules) usually gives you a much nicer API and things like change checking/idempotence. Hope that helps, thanks for your comment.
@kundansingh4419
@kundansingh4419 4 жыл бұрын
How did you setup your visual studio for ansible
@toptechskills
@toptechskills 4 жыл бұрын
Hi Kundan, I just use a standard VSCode setup with the Ansible extension by Microsoft (github.com/VSChina/vscode-ansible). Let me know if you have any more questions about the setup. Thanks!
@samuelbimbo2202
@samuelbimbo2202 6 ай бұрын
I need a simple playbook that would run this command: "netstat -tulpn | grep LISTEN" and provide the output in a file in /tmp/.
@toptechskills
@toptechskills 6 ай бұрын
The shell module is the right one to use here, just provide the argument as you would if you were using a local shell: "netstat -tulpn | grep LISTEN > /tmp/netstat_output"
@hprangana
@hprangana 3 жыл бұрын
thanks a lot
@toptechskills
@toptechskills 3 жыл бұрын
Thanks for your kind comments Isuru 🙏
@hprangana
@hprangana 3 жыл бұрын
@@toptechskills can you make stuff for devops/SRE stack. your tone is very clear and delivering is so smooth.subscribed and shared.
@toptechskills
@toptechskills 3 жыл бұрын
Looking forward to getting back into making courses, would love to make more on devops/SRE topics. Thank you very much.
@hprangana
@hprangana 3 жыл бұрын
@@toptechskills that is a wow
@gesnow
@gesnow 5 жыл бұрын
What platform and editor are you using for your demos?
@toptechskills
@toptechskills 5 жыл бұрын
Hi George, I'm using VS Code with the Ansible extension by Microsoft running on Mac OS.
@vivahernando1
@vivahernando1 5 жыл бұрын
Percy Grunwald from TopTechSkills any chance you could do a VS Code setup tutorial?
Rapidly Build & Test Ansible Roles with Molecule + Docker
20:58
Percy Grunwald from TopTechSkills
Рет қаралды 31 М.
Ansible Command Module Tutorial - Complete Beginner's Guide
10:11
Percy Grunwald from TopTechSkills
Рет қаралды 13 М.
兔子姐姐最终逃走了吗?#小丑#兔子警官#家庭
00:58
小蚂蚁和小宇宙
Рет қаралды 15 МЛН
Family Love #funny #sigma
00:16
CRAZY GREAPA
Рет қаралды 27 МЛН
Cool Parenting Gadget Against Mosquitos! 🦟👶 #gen
00:21
TheSoul Music Family
Рет қаралды 34 МЛН
Ansible Shell Module
9:16
Kristofer codes
Рет қаралды 2,1 М.
Ansible Yum Module Tutorial - Complete Beginner's Guide
9:47
Percy Grunwald from TopTechSkills
Рет қаралды 8 М.
Writing Ansible Modules
28:32
DENOG
Рет қаралды 9 М.
Ansible File Module Tutorial - Complete Beginner's Guide
15:20
Percy Grunwald from TopTechSkills
Рет қаралды 28 М.
Ansible Copy Module Tutorial - Complete Beginner's Guide
10:42
Percy Grunwald from TopTechSkills
Рет қаралды 17 М.
Ansible Apt Module Tutorial - Complete Beginner's Guide
12:01
Percy Grunwald from TopTechSkills
Рет қаралды 6 М.
What is Ansible | Ansible Playbook explained | Ansible Tutorial for Beginners
16:41
Ansible Roles - Understanding Ansible Roles
28:57
networknutsdotnet
Рет қаралды 103 М.
兔子姐姐最终逃走了吗?#小丑#兔子警官#家庭
00:58
小蚂蚁和小宇宙
Рет қаралды 15 МЛН