July Release Confetti
150+ New Hands-on Training in Aws, Linux, Azure
Red Hat, Devops, and More
Learn More

LiNUX Lab

Plays and Playbooks 2

We deploy the real environment, you take the scenario-based labs on us. Hands-on, from anywhere, at any time.

Time required: 1 Hours

Scope

Create a playbook that uploads a file (you create empty) to the target server with 0755 permissions.  Adds a line to the file with the ansible hostname and use the lineinfile module to look for the words hostname2= and if not there, then add that to the file.
Check to see if the file was created and has the content. 

Suggested Pre Requisites

 

Standard tasks for all lab servers to set them up for self use.

 

Log into the lab server as user then sudo to the root user.

 

sudo su -

 

Install ansible with

 

yum install ansible

 

Add the local server as a local group.

 

Edit the /etc/ansible/hosts file.  Put the following at the top.

 

[local]
localhost

[single]
localhost

[databases]
localhost

[other]
localhost

[temp]
localhost

 

Save the /etc/ansible/hosts file.

 

Create an ansible user to use with the labs. 

 sudo useradd -G wheel ansible

Log out and log in as the ansible user.

Create an ssh key for your user.

 

ssh-keygen

Use the ssh-copy-id command to copy your own ssh key to your own user's authority file.

 


ssh-copy-id localhost

Use the ansible all -m ping command to test connectivity to the localhost.   You should now be ready to use the lab server.

 

 

 

Objectives

Create a playbook that uploads a file (you create empty) to the target server with 0755 permissions.  Adds a line to the file with the ansible hostname and use the lineinfile module to look for the words hostname2= and if not there, then add that to the file. 
Check to see if the file was created and has the content. 

Overview

Create a playbook that uploads a file (you create empty) to the target server with 0755 permissions.  Adds a line to the file with the ansible hostname and use the lineinfile module to look for the words hostname2= and if not there, then add that to the file. 
Check to see if the file was created and has the content. 

Scenarios

1. Setup Lab server as per prerequisites.
2. Create an empty file.
3. Create a playbook that uploads the file (that you create empty) to the target server with 0755 permissions.
4. Adds a line to the file on the target so it has the ansible hostname.
5. Use the lineinfile module to look for the words hostname2= and if not there then add that to the file. Do not remove the ansible hostname previous put into the file.
6. Check to see if the file was created and has the content.

Share our Labs
Start Your Free Trial

We have the longest and most in depth courses about cloud and engineering topics on the web. All of our training content is included with every membership.