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.
Successfully complete this lab by achieving the following learning objectives:
- 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_userand change to the
ansibleuser via the
su - ansiblecommand.
Test that Ansible is working, with an ad-hoc command. One possible command to use is:
ansible all -m ping
- 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
The script should exit if no program to install has been typed in the command line.
- 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.
- 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.
- Log into node1 and node2 and Ensure the ELinks Package Has Been Installed
ansibleuser, log into the
node2servers, and ensure that ELinks has been installed.