-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathansiblegalaxy.notes
More file actions
144 lines (83 loc) · 4.43 KB
/
Copy pathansiblegalaxy.notes
File metadata and controls
144 lines (83 loc) · 4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
Ansible vs Ansible Galaxy
Ansible is a popular open-source configuration management tool that automates software provisioning, configuration management, and application deployment on machines.
Ansible Galaxy by contrast is a public repository where users can share and download Ansible roles for server configuration. Ansible Galaxy i can be found at https://galaxy.ansible.com/
Roles are a means of breaking large playbooks down into a smaller more manageable structure.
An Overview of the Ansible Role Structure
README.md – This is the Readme document for the role
tasks – contains all tasks to be executed by the Role can be stored here. /tasks/Main.yml is the entry point for the role.
handlers – contains handlers that are used by the role
defaults – contains the fefault variables for the role.
vars – contains other variables in addition to the defaults for the role.
files – contains the files which can be deployed by the role.
templates – contains templates which can be deployed by the role.
meta – You can define metadata for the role here.
tests – this contains any CI tests to be executed.
library – this contains embedded Modules and Plugins for the role which are not created by the init command.
How To Create Roles With Ansible Galaxy
The ansible-galaxy command comes pre-installed with Ansible.
You initialize a new galaxy role with:
ansible-galaxy init
A role can also be installed directly from the Ansible Galaxy repo with the command:
ansible-galaxy install <name of role>
Some commonly used ansible-galaxy commands:
ansible-galaxy -> Displays all the options available with Galaxy
ansible-galaxy list: Displays a list of the currently installed roles
ansible-galaxy remove <role>: Removes an installed role
ansible-galaxy info: Displays information about Galaxy
ansible-galaxy init: Creates a role template for submission to Galaxy
ansible-galaxy import: This galaxy command requires a login to import a role from Galaxy
ansible-galaxy install: Installs a role from Galaxy repository
Galaxy also allows you to host your own internal Galaxy server. To use the internal Galaxy server, edit the default configuration in Ansible.cfg file to point to the server address of the Galaxy internal server. By default Galaxy points to the server address galaxy.ansible.com, so you need to change this.
Begin with the init command (ansible-galaxy-init) and create a role.
For example:
kevin@asus:~/DATAVOLUME/ANSIBLECODE$ ansible-galaxy init testing
- Role testing was created successfully
kevin@asus:~/DATAVOLUME/ANSIBLECODE$
ansible-galaxy
If you wish to use a MySQL server Ansible role, search for it on the Galaxy website and click on the filter button.
You will see for example that user geerlingguy has a very popular MySQL role which you can use.
Click on geerlingguy MySQL.
Then enter on your terminal:
ansible-galaxy-mysql
This will display the installation command to install this role using ansible-galaxy.
ansible-galaxy install geerlingguy.mysql
Run the command to download and install the MySQL server role on your machine.
In this case:
kevin@asus:~/DATAVOLUME/ANSIBLECODE$ansible-galaxy install geerlingguy.mysqll
Starting galaxy role install process
kevin@asus:~/DATAVOLUME/ANSIBLECODE$
Before you can use Galaxy roles in Ansible playbooks, you first have to download the role. They will by default be placed in the default Ansible roles directory at /etc/ansible/roles.
Ansible content can also be distributed using collections. These are used for packaging and distributing playbooks, together with roles, modules, and plugins.
Here is an example of a common structure:
collection/
├── docs/
├── galaxy.yml
├── plugins/
│ ├──
modules/
│ │ └── module1.py
│ ├──
inventory/
│ └── .../
├── README.md
├── roles/
│ ├──
role1/
│ ├──
role2/
│ └── .../
├── playbooks/
│ ├──
files/
│ ├──
vars/
│ ├──
templates/
│ └── tasks/
└── tests/
Creating a Collection Structure
To install a collection on your machine, use the ansible-galaxy collection installation command:
init: Creates a basic collection structure based on Ansible’s default template or a template of your own
build: Creates a collection artifact for uploading to Galaxy or to your own repository
publish: Instructs Galaxy to publish a built collection artifact
install: Installs one or more collections