Changes

Jump to: navigation, search

OPS445 Online Lab9

141 bytes added, 01:48, 25 March 2022
no edit summary
= Investigation I: The Ansible Package =
: In this investigation, we explore the main components of the Ansible configuration management system and its operating environment. we We also study a simple playbook for managing the configuration of a CentOS 7.x VM. : You need at least two Linux systems for this lab: your account on matrix.senecacollege.ca to be used as the control machine and your assigned VM in myvmlab.senecacollege.ca as the managed machinesmachine. The Ansible package is already installed on matrix for you.
== Key Concepts when using Ansible==
* YAML - a human-readable data serialization language use used by Ansible's playbooks. To know more, your can check out the [https://en.wikipedia.org/wiki/YAML wikipedia page here] or a simple introduction [[Introduction_to_YAML|here]]
* Control machine - the host on which you use Ansible to execute tasks on the managed machines
* Managed machine - a host that is configured by the control machine
</pre>
<pre>
[raymond.chan@mtrx-node02pd lab9]$ ansible jkwok -i hosts --private-key ~/.ssh/id_rsa -u instructor -m copy -a "src=/home/raymond.chan/ops445/lab9/hosts dest=/tmp/ansible_hosts"
jkwok | CHANGED => {
"ansible_facts": {
</pre>
: '''jkwok ''' is the remote machine ID.: '''hosts ''' is the name of the ansible inventory file in the current working directory, you may also specify the inventory file with full path name, e.g. /home/raymond.chan/ops445/lab9/hosts. : '''--private-key id_ras id_rsa''' is the private key for ssh key-based authentication for connecting to the remote machine.: '''-u ''' is for specifying the user account to be used to login to the remote machine.: '''-m copy ''' is to tell ansible to use the "copy" module.: after '''-a''' is the arguments to the copy module, which specify the source file and the destination for the copy action.
: If you got the same "SUCCESS" message, login to the remote machine and check the directory "/tmp" for the file ansible_hosts.
: The following command demonstrates how to install the "epel-release" package with the "yum" module with different module arguments and under different remote user (your result may be differ from what is show below):
<pre>
[raymond.chan@mtrx-node02pd lab9]$ ansible jkwok -i hosts --private-key ~/.ssh/id_rsa -u instructor -m yum -a "name=epel-release state=present"
jkwok | FAILED! => {
"ansible_facts": {
: Add the '-b' option to tell ansible to invoke "sudo" when running the yum command on the remote machine:
<pre>
[raymond.chan@mtrx-node02pd lab9]$ ansible jkwok -i hosts --private-key ~/.ssh/id_rsa -u instructor -b -m yum -a "name=epel-release state=present"
jkwok | CHANGED => {
"ansible_facts": {
}
</pre>
: If you run the same commond command the 2nd time:
<pre>
[raymond.chan@mtrx-node02pd lab9]$ ansible jkwok -i hosts --private-key ~/.ssh/id_rsa -u instructor -b -m yum -a "name=epel-release state=present"
jkwok | SUCCESS => {
"ansible_facts": {
: Now run the similar command but with "state=latest":
<pre>
[raymond.chan@mtrx-node02pd lab9]$ ansible jkwok -i hosts --private-key ~/.ssh/id_rsa -u instructor -b -m yum -a "name=epel-release state=latest"
jkwok | SUCCESS => {
"ansible_facts": {
}
</pre>
: Depending on the status of the packages installed on your VM, the output may not exactly the same as shown above. Please read and try to understanding the meaning of the text return by ansible. If it's been updated instead, then run the command again.
== Part 4: Gather software and hardware information available on remote machine ==
: One of the core ansible module is called "setup", it is automatically called by ansible playbook to gather useful "facts" about remote hosts that can be used in ansible playbooks. It can also be executed directly by the ansible command (/usr/bin/ansible) to check out what "facts" are available on a remote host.
<pre>
[raymond.chan@mtrx-node02pd lab9]$ ansible jkwok -i hosts --private-key ~/.ssh/id_rsa -u instructor -m setup
jkwok | SUCCESS => {
"ansible_facts": {
Sample Run:
<pre>
[raymond.chan@mtrx-node02pd lab9]$ ansible-playbook -i hosts --private-key ~/.ssh/id_rsa -b motd-play.yml
PLAY [update motd file] *******************************************************************
572
edits

Navigation menu