Writing Playbooks and Roles are simple but yet to spend time for referring to the module’s man pages and need to build the logic with proper error handling. Ansible galaxy is a place where you can get the pre-written roles for various automation purposes. Galaxy hosts more than 18,000 roles written by the community members. Here are the popular categories from Ansible Galaxy and roles counts.
- system 5,198
- development 2,595
- web 2,196
- monitoring 1,156
- networking 953
- database 909
- cloud 843
- packaging 711
- docker 599
In this article, we will see that how to download and use the Ansible role from galaxy.
1. Go to Ansible galaxy portal.
2. Search for required roles. Here, let me search for “chrony” to configure on Redhat Linux
(Note – On RHEL 7 onwards, NTP has been deprecated and chrony will be the default time management protocol).
Note: Always look for the roles which are marked as build| passing.
3. Click on the role to get the installation command. You will also get the GitHub repository’s links to download.
4. click on “README” tab to know the usage of the role.
5. If your ansible server has direct internet connectivity, you could easily search and install the roles directly instead of surfing using the browser. Since we have already got the command from the portal, just execute in ansible server to install the chrony role.
[linadm@ansible-server ~]$ ansible-galaxy install ericsysmin.chrony - downloading role 'chrony', owned by ericsysmin - downloading role from https://github.com/ericsysmin/ansible-role-chrony/archive/master.tar.gz - extracting ericsysmin.chrony to /home/linadm/automation/roles/ericsysmin.chrony - ericsysmin.chrony (master) was installed successfully [linadm@ansible-server ~]$
Note: You could also download the role directly from GitHub.
6. Check the downloaded role in your roles directory.
[linadm@ansible-server roles]$ tree ericsysmin.chrony ericsysmin.chrony ├── defaults │ └── main.yml ├── handlers │ └── main.yml ├── meta │ └── main.yml ├── README.md ├── tasks │ └── main.yml ├── templates │ └── chrony.conf.j2 ├── tests │ ├── Dockerfile.centos-6 │ ├── Dockerfile.centos-7 │ ├── Dockerfile.ubuntu-14.04 │ └── test.yml └── vars ├── Debian.yml └── RedHat.yml 7 directories, 12 files [linadm@ansible-server roles]$
7. Create a playbook to call crony roles to configure on a remote server.
[linadm@ansible-server automation]$ cat chrony.yaml --- - hosts: all become: yes roles: - role: ericsysmin.chrony [linadm@ansible-server automation]$
8. Create a hosts list where you would like to install, configure chrony. Here , I have added the hosts in “lin-servers.1”
9. Run the playbook.
$ ansible-playbook -i lin-servers.1 chrony.yaml PLAY [all] **************************************************************************** TASK [Gathering Facts] **************************************************************** ok: [192.168.3.151] TASK [ericsysmin.chrony : Add the OS specific variables] *************************************************************************************** ok: [192.168.3.151] TASK [ericsysmin.chrony : Install the required packages in Redhat derivatives] ************************************************************************************** ok: [192.168.3.151] TASK [ericsysmin.chrony : Remove NTP if installed in Redhat] *************************************************************************************** changed: [192.168.3.151] TASK [ericsysmin.chrony : Install the require packages in Debian derivatives] *************************************************************************************** skipping: [192.168.3.151] TASK [ericsysmin.chrony : Copy the chrony.conf template file] *************************************************************************************** changed: [192.168.3.151] TASK [ericsysmin.chrony : Start/stop chrony service] *************************************************************************************** changed: [192.168.3.151] RUNNING HANDLER [ericsysmin.chrony : restart chrony] *************************************************************************************** changed: [192.168.3.151] PLAY RECAP **************************************************************************** 192.168.3.151 : ok=7 changed=4 unreachable=0 failed=0
10. Login to the remote servers and check the status.
$ systemctl status chronyd.service ● chronyd.service - NTP client/server Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2018-10-25 23:22:39 UTC; 4s ago Docs: man:chronyd(8) man:chrony.conf(5) Process: 45621 ExecStartPost=/usr/libexec/chrony-helper update-daemon (code=exited, status=0/SUCCESS) Process: 45617 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUCCESS) Main PID: 45619 (chronyd) Tasks: 1 Memory: 360.0K CGroup: /system.slice/chronyd.service └─45619 /usr/sbin/chronyd
Hope this article is informative to you. Share it ! Comment it !! Be Social !!!
Leave a Reply