- Lab
- A Cloud Guru
Deploying Ansible
Ansible is a powerful automation tool that can be used for managing configuration state or even performing coordinated multi-system deployments. This activity is intended to provide the steps to get started with a simple Ansible configuration.
Path Info
Table of Contents
-
Challenge
Install Ansible on the control host.
Run the following commands on the control host:
sudo yum install epel-release
sudo yum install ansible
-
Challenge
Create an `ansible` user on both the control host and workstation host being sure to set a password you can remember.
On each host, run the noted commands below. Make sure you set a password you can remember (you will need it later).
Assuming you are logged in as
cloud_user
:sudo useradd ansible
sudo passwd ansible
-
Challenge
Configure a pre-shared key for Ansible that allows the user to log in from `control` to `workstation` without a password.
Assuming you are logged into control as
cloud_user
, run the following commands providing the appropriate passwords when prompted and default options otherwise:sudo -i -u ansible
(providecloud_user
asudo
password)ssh-keygen
(accept default options by pressing enter )ssh-copy-id workstation
(provideansible
user a password)logout
-
Challenge
Configure the Ansible user on the workstation host so that Ansible may sudo without a password.
- Log into the workstation host as
cloud_user
and run the following commands:
sudo visudo
- Add text at the end of the file that is opened:
ansible ALL=(ALL) NOPASSWD: ALL
- Save file:
(:wq in vim)
- Log into the workstation host as
-
Challenge
Create a simple inventory in `/home/ansible/inventory` consisting of only the `workstation` host.
- On the control host as the ansible user run the following commands:
vim /home/ansible/inventory
(note: you may use any text editor with which you are comfortable)- Add the text "workstation" to the file and save using
(:wq in vim)
.
-
Challenge
Write an Ansible playbook in `/home/ansible/git-setup.yml` on the control node that installs `git` on `workstation` then execute the playbook.
- On the control host as the ansible user run the following commands:
vim /home/ansible/git-setup.yml
(You may use any text editor with which your are comfortable.)
- Add the following text to the file:
--- # install git on target host - hosts: workstation become: yes tasks: - name: install git yum: name: git state: latest
-
Save
(:wq in vim)
and quit the text editor. -
Run
ansible-playbook -i /home/ansible/inventory /home/ansible/git-setup.yml
.
- On the control host as the ansible user run the following commands:
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.