When we refer to the controller
, that means that we speak about the machine that executes the Ansible playbooks
and roles
and which owns the inventory. The hosts
are the machines where the playbooks and roles are executed against.
The exception goes to the playbooks that are executed against localhost
. This special host is referred to the controller
.
ℹ️
|
Check the Ansible requirement page for Python compatibility ! |
In order to play with the playbooks/roles of this project, it is needed to:
-
Install Ansible
-
Preferrably by using the Python Virtual Environments method
-
For more installation check the Ansible Installation Guide
-
Ansible uses Python, so check the Ansible Python 3 Support page for more information.
-
-
Install
passwordstore
-
This project uses [pass](https://www.passwordstore.org/) to store passwords and certificates related to the project itself.
-
More information on installing pass in the Download section of the [passwordstore web page](https://www.passwordstore.org/)
-
-
Clone the
passstore
project from GitLab. -
Install the
snowdrop/cloud_infra
Ansible Collection
ℹ️
|
Since passwordstore is integrated with git, all changes made locally to a pass repository are automatically committed to the local git repo. |
|
Don’t forget to |
This project suggests using a python virtual environment to manage all the python dependencies.
This section describes the procedure to create a virtual environment for using with the project.
First create the .snowdrop-venv
virtual environment.
ℹ️
|
This command only needs to be executed the first time. After
being created the virtual environment status will be stored at
the |
.snowdrop-venv
virtual environmentpython3 -m venv .snowdrop-venv
Then activate the virtual environment to be able to use it. Activating is done by executing the following command.
.snowdrop-venv
virtual environmentsource .snowdrop-venv/bin/activate
After this the virtual environment name will show up on the bash prompt (e.g. (.snowdrop-venv) [janedoe@mycomputer k8s-infra]$
).
Once using the python virtual environment install the requirements.
ℹ️
|
This command only needs to be executed the first time. |
python3 -m pip install -r requirements.txt
ansible-galaxy collection install -r ./collections/requirements.yml --upgrade
To deactivate the python virtual environment execute the following command.
deactivate
As a result the .snowdrop-venv
reference on the bash prompt will disappear.
|
Requires: Python Virtual Environment active. |
Before building the collection make sure no previous versions have been built.
rm -f build/snowdrop-cloud_infra-*.tar.gz
To build the collection execute the following ansible-galaxy
command.
snowdrop/cloud_infra
collectionansible-galaxy collection build ansible/ansible_collections/snowdrop/cloud_infra --output build/ --force
This will generate a .tar.gz
file with name snowdrop-cloud_infra-<version>.tar.gz
on the ./build/ subfolder of the k8s-infra
repository.
Finally install the collection.
ansible-galaxy collection install $(find . -name snowdrop-cloud_infra-*.tar.gz) --upgrade
Provisioning and accessing a server requires several steps, each of which will be covered in this section.
-
Manage Ansible Inventory groups […](Group management in ansible)
-
Manage Ansible Inventory host records […](#host-management-in-ansible)
-
Create Server in Cloud Provider […]([Create server])
-
Secure Host […](Secure host)
-
Install Software […](Install software)
Groups are defined in the hosts.yml
file that exists in the inventory folder inventory/hosts.yml. The 2 main goals of groups is to apply variable values and filter playbook execution.
The usage for groups is to:
-
define the provider of each host and the associated information
-
define information related to groups of applications
Click to see more information related to the providers hosts group
There can are different groups for the providers, ATTOW two providers exist, openstack and hezner. The goal is to provide variables that are required for each provider such as the provider variable which contains the provider name.
inventory/hosts.yml
filelink:inventory/hosts.yml[role=include]
Another existing group is k8s
are associated with kubernetes and assign the kubernetes version or ports to be open.
Click to see more information related to the k8s (kubernetes) group
There can are different groups for the providers, ATTOW two providers exist, openstack and hezner. The goal is to provide variables that are required for each provider such as the provider variable which contains the provider name.
inventory/hosts.yml
fileall:
children:
link:inventory/hosts.yml[role=include]
For each k8s version there is associated information defined by common variables.
|
The usage of group variables to keep this information is subject to be reviewed on the short term. More information at GitHub Issue 335. |
link:inventory/hosts.yml[role=include]
If it would be required to support a new kubernetes version than a new set of variables should be added to the inventory file. For instance, preparing the
installation for version 1.17
would require adding a new group as child of the k8s
group. It might also be required to adjust the dashboard and flannel values.
k8s_1.30:
vars:
k8s_version: 1.30.1
k8s_dashboard_version: v3.1.2
coreos_flannel_sha_commit: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
The Ansible host inventory is generated from the hosts.yml
file as well as the passwordstore database. The
inventory is dynamically generated by this python script.
The location of the inventory is defined at the ansible.cfg
configuration file at the root of the project.
ansible.cfg
link:../ansible.cfg[role=include]
The first step is to add the host to the Ansible inventory but also to create the needed keys under the password store. This section describes how to maintain our hosts and their use.
The passwordstore inventory should be updated whenever a VM is created and/or
updated. For instances, the playbook that creates an OpenStack VM
(openstack_vm_create_passwordstore.yml
)
also calls the passwordstore playbook for adding the host to the inventory.
The same happens in the playbook that removes an OpenStack VM
(openstack_vm_remove_passwordstore.yml
).
link:playbook/openstack/openstack_vm_create_passwordstore.yml[role=include]
Nevertheless whis can be done manually and the next sections will describe the process.
As commented before, the host information (user, pwd, ssh port, …) is obtained from the github passwordstore
team [project](https://github.com/snowdrop/pass).
Because a host can already be defined under the store, prior to execute the playbook creating a host, check the content of the store using the following command
pass hetzner
hetzner
├── ...
├── host-1
│ ├── ...
├── host-2
│ ├── ...
According to what you will find under the Hetzner
level, then 2 scenario will take place:
-
The host exists. Jump to the Import a host section;
-
The host doesn’t exist. Create a new host as documented under the section Create a host.
ℹ️
|
Check the [team password store documentation](https://github.com/snowdrop/pass) if it is not yet installed on your laptop. |
|
Whenever a command to create a host and password entries took place, then push the content using the command |
If a host has already been created, it can be imported within the inventory using the command:
ansible-playbook ansible/playbook/passstore_controller_inventory.yml -e vm_name=<VM_NAME> -e pass_provider=hetzner
where <VM_NAME>
corresponds to the host key created under hetzner
.
ℹ️
|
The playbook used is the same as the one described in the Create a host section but without the |
If the host doesn’t exist it must be generated and added to the Ansible inventory.
This is done using the passstore_controller_inventory
playbook. More information on how to use this playbook in the [passstore_controller_inventory
section](#passstore_controller_inventory).
This is done using the passstore_controller_inventory_remove
playbook. More information on how to use this playbook in the [passstore_controller_inventory_remove
section](#passstore_controller_inventory_remove).
ansible-playbook ansible/playbook/passstore_controller_inventory_remove.yml -e vm_name=<vm_name> -e pass_provider=<provider>
Once the inventory is defined the server can be provisioned, if it isn’t.
There should be different playbooks for each of the providers so check the corresponding provider:
Once the server is created it must be securized. More information on the next section.
Host securization is of utmost importance. For this reason a specific playbook and roles have been generated to perform this task.
For the execution of the securization check the [sec_host
playbook section](#sec_host).
Ansible Collections: ansible_collections
Ansible Inventory: inventory
Ansible Playbooks: playbook
Ansible Roles: roles
Build a collection
ansible-galaxy collection build ansible/ansible_collections/snowdrop/godaddy --output build/ --force
Install a collection
ansible-galaxy collection install build/snowdrop-godaddy-$(yq -r .version ansible/ansible_collections/snowdrop/godaddy/galaxy.yml).tar.gz --upgrade