Open main menu

CDOT Wiki β

Changes

OPS445 Online Lab9

1 byte removed, 02:08, 25 March 2022
m
no edit summary
<pre>
...
[ops445bops445]jkwok vmlab ansible_host=myvmlab.senecacollege.ca ansible_port=78507890cdee myvm ansible_host=myvmlab.senecacollege.ca ansible_port=78747654
...
</pre>
<pre>
[raymond.chan@mtrx-node02pd lab9]$ ansible jkwok vmlab -i hosts --private-key ~/.ssh/id_rsa -u instructor -m copy -a "src=/home/raymond.chan/ops445/lab9/hosts dest=/tmp/ansible_hosts"jkwok vmlab | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
</pre>
: '''jkwokvmlab''' 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_rsa''' is the private key for ssh key-based authentication for connecting to the remote machine.
: 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 vmlab -i hosts --private-key ~/.ssh/id_rsa -u instructor -m yum -a "name=epel-release state=present"jkwok vmlab | FAILED! => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
: 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 vmlab -i hosts --private-key ~/.ssh/id_rsa -u instructor -b -m yum -a "name=epel-release state=present"jkwok vmlab | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
: If you run the same command the 2nd time:
<pre>
[raymond.chan@mtrx-node02pd lab9]$ ansible jkwok vmlab -i hosts --private-key ~/.ssh/id_rsa -u instructor -b -m yum -a "name=epel-release state=present"jkwok vmlab | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
: Now run the similar command but with "state=latest":
<pre>
[raymond.chan@mtrx-node02pd lab9]$ ansible jkwok vmlab -i hosts --private-key ~/.ssh/id_rsa -u instructor -b -m yum -a "name=epel-release state=latest"jkwok vmlab | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
: 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 vmlab -i hosts --private-key ~/.ssh/id_rsa -u instructor -m setupjkwok vmlab | SUCCESS => {
"ansible_facts": {
"ansible_all_ipv4_addresses": [
---
- name: update motd file
hosts: jkwokvmlab
user: instructor
become: yes
TASK [Gathering Facts] ********************************************************************
ok: [jkwokvmlab]
TASK [setup a MOTD] ***********************************************************************
changed: [jkwokvmlab]
PLAY RECAP ********************************************************************************
jkwok vmlab ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
</pre>
572
edits