hyperion-rt / hyperion

Hyperion Radiative Transfer Code
http://www.hyperion-rt.org
BSD 2-Clause "Simplified" License
52 stars 26 forks source link

Installation and working with Ansible #193

Open misterbaanu opened 7 years ago

misterbaanu commented 7 years ago

Installing Ansible

The installation of the Ansible package is only required on the host that generated the SSH key in Example 1. If you are running Fedora, you can issue the following command:

sudo dnf install ansible -y If you run CentOS, you need to configure Extra Packages for Enterprise Linux (EPEL) repositories:

sudo yum install epel-release -y Then you can install Ansible with yum:

sudo yum install ansible -y For Ubuntu-based systems, you can install Ansible from the PPA:

sudo apt-get install software-properties-common -y sudo apt-add-repository ppa:ansible/ansible sudo apt-get update sudo apt-get install ansible -y If you are using macOS, the recommended installation is done via Python PIP:

sudo pip install ansible See the Ansible installation documentation for other distributions.

Working with Ansible Inventory

Ansible uses an INI-style file called an Inventory to track which servers it may manage. By default this file is located in /etc/ansible/hosts. In this article, I will use the Ansible Inventory shown in Example 2 to perform actions against the desired hosts (which has been paired down for brevity):

Example 2: Ansible hosts file

[arch] nextcloud prometheus desktop1 desktop2 vm-host15

[fedora] netflix

[centos] conan confluence 7-repo vm-server1 gitlab

[ubuntu] trusty-mirror nwn kids-tv media-centre nas

[satellite] satellite

[ocp] lb00 ocp_dns master01 app01 infra01 Each group, which is denoted via square brackets and a group name (such as [group1]), is an arbitrary group name that can be applied to a set of servers. A server can exist in multiple groups without issue. In this case, I have groups for operating systems (arch, ubuntu, centos, fedora), as well as server function (ocp, satellite). The Ansible host file can handle significantly more advanced functionality than what I am using. For more information, see the Inventory documentation.

Running ad hoc commands

After you have copied your SSH keys to all the servers in your inventory, you are ready to start using Ansible. A basic Ansible function is the ability to run ad hoc commands. The syntax is:

ansible -a "some command" For example, if you want to update all of the CentOS servers, you might run:

ansible centos -a 'yum update -y' Note: Having group names based on the operating system of the server is not necessary. As I will discuss, Ansible Facts can be used to gather this information; however, issuing ad hoc commands becomes more complex when trying to use Facts, and so for convenience I recommend creating a few groups based on operating system if you manage a heterogeneous environment.

This will loop over each of the servers in the group centos and install all of the updates. A more useful ad hoc command would be the Ansible ping module, which is used to verify that a server is ready to receive commands:

ansible all -m ping This will result in Ansible attempting to log in via SSH to all of the servers in your inventory. Truncated output for the ping command can be seen in Example 3.

Example 3: Ansible ping command output

nwn | SUCCESS => { "changed": false, "ping": "pong" } media-centre | SUCCESS => { "changed": false, "ping": "pong" } nas | SUCCESS => { "changed": false, "ping": "pong" } kids-tv | SUCCESS => { "changed": false, "ping": "pong" } ... The ability to run ad hoc commands is useful for quick tasks, but what if you want to be able to run the same tasks later, in a repeatable fashion? For that Ansible implements playbooks.