- Lab
- A Cloud Guru
Ad-Hoc Ansible Shell Scripts
One of the keys to success with Ansible is being able to run `ad-hoc` commands and in this particular exercise we will make use of scripting and ad-hoc commands to perform tasks. The value of `ad-hoc` commands in scripts is underscored by the fact that it is an objective of the *Red Hat Certified Ansible Specialist* exam. In this lab we will create a bash script and use it to perform Ansible Ad-hoc tasks. Note: Ansible has been setup and configured for use. *This course is not approved or sponsored by Red Hat.*
Path Info
Table of Contents
-
Challenge
Sign onto the Ansible Control Node Server as cloud_user and Change to the ansible User, Then Test Ansible Has Been Set Up
Sign into the server called Ansible Control Node as
cloud_user
and change to theansible
user via thesu - ansible
command.Test that Ansible is working, with an ad-hoc command. One possible command to use is:
ansible all -m ping
-
Challenge
Create a Bash Script Called install-package.sh That Accepts a Parameter and Uses an Ad-Hoc Ansible Command to Install Software
Using Bash, create a script that accepts a variable on the command line and uses an ad-hoc Ansible command to install software on the
node1
andnode2
servers.The script should exit if no program to install has been typed in the command line.
-
Challenge
Test the Script to Ensure It Will Exit If a Command Line Argument Has Not Been Entered
If no command line argument has been entered, the script should exit.
-
Challenge
Make Sure the Script is Executable and Use it to Install Elinks on the node1 and node2 Servers
Ensure the script is executable, and run it to install ELinks on the nodes.
-
Challenge
Log into node1 and node2 and Ensure the ELinks Package Has Been Installed
As the
ansible
user, log into thenode1
andnode2
servers, and ensure that ELinks has been installed.
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.