====== Comandos essenciais do Ansible Galaxy ======
$ cd /etc/ansible/roles
$ sudo ansible-galaxy role --help
usage: ansible-galaxy role [-h] ROLE_ACTION ...
positional arguments:
ROLE_ACTION
init Initialize new role with the base structure of a role.
remove Delete roles from roles_path.
delete Removes the role from Galaxy. It does not remove or alter the actual GitHub repository.
list Show the name and version of each role installed in the roles_path.
search Search the Galaxy database by tags, platforms, author and multiple keywords.
import Import a role into a galaxy server
setup Manage the integration between Galaxy and the given source.
info View more details about a specific role.
install Install role(s) from file(s), URL(s) or Ansible Galaxy
options:
-h, --help show this help message and exit
Principais subcomandos:
* **init:** Inicializa um nova Role;
* **remove:** Exclui uma Role de roles_path;
* **delete:** Remove a Role do Ansible Galaxy(não remove ou altera o repositório real do GitHub);
* **list:** Lista as Roles instaladas no roles_path;
* **search:** Pesquisa uma Role no banco de dados do Ansible Galaxy por tags, plataformas, autor e várias palavras-chave;
* **import:** Importa uma Role para um servidor galaxy;
* **setup:** Gerencia a integração entre o Ansible Galaxy e a fonte fornecida;
* **info:** Exibe detalhes sobre uma Role específica;
* **install:** Instala a Role disponível no banco de dados do Ansible Galaxy.
==== Listar e pesquisar Roles ====
Para listar as Roles disponíveis no sistema, execute o subcomando ''role list'':
$ sudo ansible-galaxy role list
# /etc/ansible/roles
Para pesquisar uma determinada Role disponível no Ansible Galaxy, execute o subcomando ''role search'':
$ sudo ansible-galaxy role search ntpdate
Found 18 roles matching your search:
Name Description
---- -----------
alvarobacelar.toolsbasicforserver your description
amtega.chrony Configure chrony
amtega.ntp Configure NTP
ANXS.ntp install and configure ntp
cfawcett82.linux_join_domain_role_survey Role for joining EL7.x and 8.x to Windows AD using realm join
galexrt.ansible-ntpdate Ansible NTP client basic setup role.
jhu-sheridan-libraries.ntp Ansible role to install and configure a simple ntp client
lindahu1.common Ansible role to install and configure some basic OS setting for an initial server.
NIXKnight.Ansible-LinuxCommon Configuring shell environment and installing some very basic utilities on a new Linux system.
Rheinwerk.ntpdate_cron Installs an ntpdate hourly cronjob on Ubuntu
roquie.ansible-kontena-agent Install Kontena Agent on node-server.
roquie.ansible-ntpdate Ansible NTP client basic setup role.
ry-gon.perfsonar-docker perfSONAR Testpoint and Toolkit, designed for Docker
semuadmin.webmin webmin role
triviadata.ntpdate Ansible role synchronizing host via NTP for Linux
turcumihaiioan.system_package role for ansible.builtin.package
vbotka.freebsd_postinstall Postinstallation configuration of FreeBSD.
vbotka.freebsd_wpa_cli FreeBSD. RC system and wpa_cli action_file configure wlan devices.
Para pesquisar uma determinada Role a partir de um autor, use a flag ''--author'':
$ sudo ansible-galaxy role search --author geerlingguy
Found 101 roles matching your search:
Name Description
---- -----------
geerlingguy.adminer Installs Adminer for Database management.
geerlingguy.ansible Ansible for RedHat/CentOS/Debian/Ubuntu.
geerlingguy.apache Apache 2.x for Linux.
geerlingguy.apache-php-fpm Apache 2.4+ PHP-FPM support for Linux.
geerlingguy.aws-inspector AWS Inspector installation for Linux.
geerlingguy.awx Installs and configures AWX (Ansible Tower's open source version).
geerlingguy.awx-container Ansible AWX container for Docker.
geerlingguy.backup Backup for Simple Servers.
geerlingguy.bad_judgement DO NOT USE THIS ROLE! It is for demonstration purposes.
geerlingguy.blackfire Blackfire installation for Linux
[...]
Para pesquisar uma determinada Role a partir de um autor e uma tag, use as flags ''--author'' e ''--galaxy-tags'':
$ sudo ansible-galaxy role search --author geerlingguy --galaxy-tags ntp
Found 1 roles matching your search:
Name Description
---- -----------
geerlingguy.ntp NTP installation and configuration for Linux.
==== Exibir informações e instalar Roles ====
Para exibir informações sobre uma Role disponível no Ansible Galaxy, execute o subcomando ''role info'':
$ sudo ansible-galaxy role info geerlingguy.ntp
Role: geerlingguy.ntp
description: NTP installation and configuration for Linux.
active: True
commit: d9bc078d9972f0d28ab2301fb36783a12a10ee13
commit_message: Merge pull request #110 from blmhemu/master
Fixes service not found issue.
commit_url: https://api.github.com/repos/geerlingguy/ansible-role-ntp/git/commits/d9bc078d9972f0d28ab2301fb36783a12a10ee13
company: Midwestern Mac, LLC
created: 2014-03-05T15:50:12.955490Z
download_count: 3407963
forks_count: 207
github_branch: master
github_repo: ansible-role-ntp
github_user: geerlingguy
id: 464
imported: 2022-01-19T10:48:24.353480-05:00
is_valid: True
issue_tracker_url: https://github.com/geerlingguy/ansible-role-ntp/issues
license: license (BSD, MIT)
min_ansible_version: 2.4
modified: 2022-01-19T15:48:24.358346Z
open_issues_count: 3
path: ('/etc/ansible/roles',)
role_type: ANS
stargazers_count: 236
travis_status_url:
Para instalar uma Role disponível no Ansible Galaxy, execute o subcomando ''role install'':
$ sudo ansible-galaxy role install geerlingguy.ntp
Starting galaxy role install process
- downloading role 'ntp', owned by geerlingguy
- downloading role from https://github.com/geerlingguy/ansible-role-ntp/archive/2.3.1.tar.gz
- extracting geerlingguy.ntp to /etc/ansible/roles/geerlingguy.ntp
- geerlingguy.ntp (2.3.1) was installed successfully
Verifique que agora possuímos uma nova Role:
$ sudo ansible-galaxy role list
# /etc/ansible/roles
- geerlingguy.ntp, 2.3.1
$ tree /etc/ansible/roles/geerlingguy.ntp/
/etc/ansible/roles/geerlingguy.ntp/
├── LICENSE
├── README.md
├── defaults
│ └── main.yml
├── handlers
│ └── main.yml
├── meta
│ └── main.yml
├── molecule
│ └── default
│ ├── converge.yml
│ └── molecule.yml
├── tasks
│ └── main.yml
├── templates
│ ├── chrony.conf.j2
│ ├── clock.j2
│ └── ntp.conf.j2
└── vars
├── Archlinux.yml
├── Debian.yml
├── FreeBSD.yml
├── RedHat.yml
└── Suse.yml
8 directories, 16 files
===== Aplicar configurações e remover uma Role =====
Para finalizar, é preciso criar um arquivo responsável em carregar a Role e definir em qual máquina ela será aplicada.
$ cat ~/roles/playbooks/ntp.yml
---
- hosts: local
roles:
- geerlingguy.ntp
$ sudo ansible-playbook --syntax-check ~/roles/playbooks/ntp.yml
playbook: /home/vagrant/roles/playbooks/ntp.yml
$ sudo ansible-playbook ~/roles/playbooks/ntp.yml
PLAY [local] ****************************************************************************************************************************************************************************************************
TASK [Gathering Facts] ******************************************************************************************************************************************************************************************
ok: [ansible-server]
TASK [geerlingguy.ntp : Include OS-specific variables.] *********************************************************************************************************************************************************
ok: [ansible-server]
TASK [geerlingguy.ntp : Set the ntp_driftfile variable.] ********************************************************************************************************************************************************
ok: [ansible-server]
TASK [geerlingguy.ntp : Set the ntp_package variable.] **********************************************************************************************************************************************************
ok: [ansible-server]
TASK [geerlingguy.ntp : Set the ntp_config_file variable.] ******************************************************************************************************************************************************
ok: [ansible-server]
TASK [geerlingguy.ntp : Set the ntp_daemon variable.] ***********************************************************************************************************************************************************
ok: [ansible-server]
TASK [geerlingguy.ntp : Ensure NTP package is installed.] *******************************************************************************************************************************************************
changed: [ansible-server]
TASK [geerlingguy.ntp : Ensure tzdata package is installed (Linux).] ********************************************************************************************************************************************
ok: [ansible-server]
TASK [geerlingguy.ntp : Set timezone.] **************************************************************************************************************************************************************************
ok: [ansible-server]
TASK [geerlingguy.ntp : Populate service facts.] ****************************************************************************************************************************************************************
ok: [ansible-server]
TASK [geerlingguy.ntp : Disable systemd-timesyncd if it's running but ntp is enabled.] **************************************************************************************************************************
ok: [ansible-server]
TASK [geerlingguy.ntp : Ensure NTP is running and enabled as configured.] ***************************************************************************************************************************************
ok: [ansible-server]
TASK [geerlingguy.ntp : Ensure NTP is stopped and disabled as configured.] **************************************************************************************************************************************
skipping: [ansible-server]
TASK [geerlingguy.ntp : Generate ntp configuration file.] *******************************************************************************************************************************************************
skipping: [ansible-server]
PLAY RECAP ******************************************************************************************************************************************************************************************************
ansible-server : ok=12 changed=1 unreachable=0 failed=0 skipped=2 rescued=0 ignored=0
$ sudo ansible local -m shell -a 'ntpq -p'
ansible-server | CHANGED | rc=0 >>
remote refid st t when poll reach delay offset jitter
==============================================================================
0.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 +0.000 0.000
1.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 +0.000 0.000
2.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 +0.000 0.000
3.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 +0.000 0.000
ntp.ubuntu.com .POOL. 16 p - 64 0 0.000 +0.000 0.000
+ec2-52-67-171-2 23.254.215.107 3 u 67 64 3 84.320 +0.705 1.307
+ec2-54-232-82-2 200.160.7.197 2 u 68 64 3 83.373 +1.154 1.264
+ns1.nvsul.com.b 200.160.7.197 2 u 4 64 7 93.919 +0.579 1.613
+b.ntp.br 200.160.7.186 2 u 5 64 7 123.524 +1.347 1.462
#time100.stupi.s .PPS. 1 u 67 64 3 297.391 +2.784 1.003
+a.ntp.br 200.160.7.186 2 u 6 64 7 82.054 +0.615 1.267
+rockstor.vbd.op 129.134.28.123 2 u 8 64 7 82.075 +1.057 1.233
+lrtest2.ntp.ifs 143.107.229.211 2 u 7 64 7 89.651 +0.986 1.328
+b.st1.ntp.br 200.160.7.186 2 u 7 64 7 95.013 +1.233 1.338
*a.st1.ntp.br .ONBR. 1 u 6 64 7 82.034 +0.963 1.001
+138-36-164-35.o 200.160.7.197 2 u 8 64 7 82.082 +1.107 1.220
+66.90.70.34 17.253.10.149 2 u 10 64 7 81.742 +1.106 1.288
pugot.canonical 17.253.34.253 2 u 17 64 7 255.607 +0.675 1.326
185.125.190.57 48.134.154.62 2 u 15 64 7 255.544 +1.738 1.686
alphyn.canonica 193.204.114.232 2 u 15 64 7 196.469 +0.437 1.474
185.125.190.58 167.28.20.25 2 u 13 64 7 255.783 +1.241 1.468
Para remover uma Role disponível no sistema, execute o subcomando ''role remove'':
$ sudo ansible-galaxy role remove geerlingguy.ntp
- successfully removed geerlingguy.ntp
$ sudo ansible-galaxy role list
# /etc/ansible/roles