Changes

Jump to: navigation, search

OPS435 Online Lab9

2,762 bytes added, 00:52, 26 March 2021
Part 3: Sample runs for using some Ansible's built-in modules
: If you got the same "SUCCESS" message, login to the remote machine and check the directory "/tmp" for the file ansible_hosts.
== Part 3: Sample runs for using some Ansible's built-in modules ==
: You can get a complete list of all the ansible modules installed on you system with the following command:<source lang="bash">
ansible-doc --list_files
</source>
: "yum" is a built-in stable ansible module. You can get the detail information about any ansible module with the ansible-doc, try the following commandcommands to see the documentation and examples for using the copy and yum modules:<source lang="bash"> ansible-doc copy 
ansible-doc yum
</source>
: 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>
[rchanraymond.chan@centos7 ansiblemtrx-node02pd lab9]$ ansible 192.168.99.153 jkwok -i hosts --private-key id_rsa -u instructor -m yum -a "name=epel-release state=present"192.168.99.153 jkwok | SUCCESS FAILED! => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" },
"changed": false,
"changes": {
"installed": [
"epel-release"
]
},
"msg": "You need to be root to perform this command.\n",
"rc": 1,
"results": [
"Loaded plugins: fastestmirror\n"
]
}
</pre>
: 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 id_rsa -u instructor -b -m yum -a "name=epel-release state=present"
jkwok | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"changes": {
"installed": [
"epel-release"
]
},
"msg": "",
"rc": 0,
"results": [
"Loaded plugins: fastestmirror\nLoading mirror speeds from cached hostfile\n * base: mirror.netflash.net\n * extras: mirror.netflash.net\n * updates: mirror.calgah.com\nResolving Dependencies\n--> Running transaction check\n---> Package epel-release.noarch 0:7-11 will be installed\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package Arch Version Repository Size\n================================================================================\nInstalling:\n epel-release noarch 7-11 extras 15 k\n\nTransaction Summary\n================================================================================\nInstall 1 Package\n\nTotal download size: 15 k\nInstalled size: 24 k\nDownloading packages:\nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n Installing : epel-release-7-11.noarch 1/1 \n Verifying : epel-release-7-11.noarch providing 1/1 \n\nInstalled:\n epel-release is already installed.noarch 0:7-11 \n\nComplete!\n"
]
}
</pre>: If you run the same commond the 2nd time:<pre>[rchanraymond.chan@centos7 ansiblemtrx-node02pd lab9]$ ansible 192.168.99.153 jkwok -i hosts --private-key id_rsa -u instructor -b -m yum -a "name=epel-release state=present" -u root192.168.99.153 jkwok | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" },
"changed": false,
"msg": "",
]
}
</pre>: Now run the similar command but with "state=latest":<pre>[rchanraymond.chan@centos7 ansiblemtrx-node02pd lab9]$ ansible 192.168.99.153 jkwok -i hosts --private-key id_rsa -u instructor -b -m yum -a "name=epel-release state=latest" -u root192.168.99.153 jkwok | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" },
"changed": false,
"changes": {
"installed": [],
"updated": []
},
"msg": "",
"rc": 0,
}
</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.
== Part 4: Gather software and hardware information available on remote machine ==
1,760
edits

Navigation menu