You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/books/learning_ansible/01-basic.md
+62-31Lines changed: 62 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,7 +37,7 @@ It uses the **SSH** protocol to remotely configure Linux clients or the **WinRM*
37
37
38
38
The opening of SSH or WinRM flows to all clients from the Ansible server, makes it a critical element of the architecture that must be carefully monitored.
39
39
40
-
As Ansible is push-based, it will not keep the state of its targeted servers between each of its executions. On the contrary, it will perform new state checks each time it is executed. It is said to be stateless.
40
+
As Ansible is mainly push-based, it will not keep the state of its targeted servers between each of its executions. On the contrary, it will perform new state checks each time it is executed. It is said to be stateless.
41
41
42
42
It will help you with:
43
43
@@ -85,26 +85,59 @@ To offer a graphical interface to your daily use of Ansible, you can install som
85
85
86
86
## Installation on the management server
87
87
88
-
Ansible is available in the _EPEL_ repository but comes as version 2.9.21, which is quite old now. You can see how this is done by following along here, but skip the actual installation steps, as we will be installing the latest version. The _EPEL_ is required for both versions, so you can go ahead and install that now:
88
+
Ansible is available in the _EPEL_ repository, but may sometimes be too old for the current version, and you'll want to work with a more recent version.
89
+
90
+
We will therefore consider two types of installation:
91
+
92
+
* the one based on EPEL repositories
93
+
* one based on the `pip` python package manager
94
+
95
+
The _EPEL_ is required for both versions, so you can go ahead and install that now:
89
96
90
97
* EPEL installation:
91
98
92
99
```
93
100
$ sudo dnf install epel-release
94
101
```
95
-
If we were installing Ansible from the _EPEL_ we could do the following:
102
+
103
+
### Installation from EPEL
104
+
105
+
If we install Ansible from the _EPEL_, we can do the following:
python version = 3.11.2 (main, Jun 22 2023, 04:35:24) [GCC 8.5.0 20210514
121
+
(Red Hat 8.5.0-18)] (/usr/bin/python3.11)
122
+
jinja version = 3.1.2
123
+
libyaml = True
124
+
125
+
$ python3 --version
126
+
Python 3.6.8
101
127
```
128
+
129
+
Please note that ansible comes with its own version of python, different from the system version of python (here 3.11.2 vs 3.6.8). You'll need to take this into account when pip-installing the python modules required for your installation (e.g. `pip3.11 install PyVMomi`).
130
+
131
+
### Installation from python pip
132
+
102
133
As we want to use a newer version of Ansible, we will install it from `python3-pip`:
103
134
104
135
!!! Note
105
136
106
137
Remove Ansible if you have installed it previously from _EPEL_.
107
138
139
+
At this stage, we can choose to install ansible with the version of python we want.
`python3-argcomplete` is provided by _EPEL_. Please install epel-release if not done yet.
115
148
This package will help you complete Ansible commands.
116
149
117
-
Before we actually install Ansible, we need to tell Rocky Linux that we want to use the newly installed version of Python. The reason is that if we continue to the install without this, the default python3 (version 3.6 as of this writing), will be used instead of the newly installed version 3.8. Set the version you want to use by entering the following command:
python version = 3.8.16 (default, Jun 25 2023, 05:53:51) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)]
168
+
jinja version = 3.1.2
143
169
libyaml = True
144
170
```
145
171
172
+
!!! NOTE
173
+
174
+
The manually installed version in our case is older than the version packaged by RPM because we used an older version of python. This observation will vary with time and the age of the distribution and the python version of course.
175
+
146
176
## Configuration files
147
177
148
178
The server configuration is located under `/etc/ansible`.
@@ -152,19 +182,10 @@ There are two main configuration files:
152
182
* The main configuration file `ansible.cfg` where the commands, modules, plugins, and ssh configuration reside;
153
183
* The client machine management inventory file `hosts` where the clients, and groups of clients are declared.
154
184
155
-
As we installed Ansible with `pip`, those files do not exist. We will have to create them by hand.
156
-
157
-
An example of the `ansible.cfg`[is given here](https://github.com/ansible/ansible/blob/devel/examples/ansible.cfg) and an example of the `hosts`[file here](https://github.com/ansible/ansible/blob/devel/examples/hosts).
You can also use the `ansible-config` command to generate a new configuration file:
185
+
If Ansible was installed via its RPM package, then the configuration file will have been automatically created. With a `pip` installation, this file does not exist. We'll have to create it by hand thanks to the `ansible-config` command:
The `--disabled` option allows you to comment out the set of options by prefixing them with a `;`.
187
208
209
+
!!! NOTE
210
+
211
+
You can also choose to embed the ansible configuration in your code repository, with ansible loading the configuration files it finds in the following order (processing the first file it finds and ignoring the rest):
212
+
213
+
* if the environment variable `$ANSIBLE_CONFIG` is set, load the specified file.
214
+
* `ansible.cfg` if exists in the current directory.
215
+
* `~/.ansible.cfg` if exists (in the user’s home directory).
216
+
217
+
If none of these three files is found, the default file is loaded.
218
+
188
219
### The inventory file `/etc/ansible/hosts`
189
220
190
221
As Ansible will have to work with all your equipment to be configured, it is very important to provide it with one (or more) well-structured inventory file(s), which perfectly matches your organization.
0 commit comments