Goal: There is a directory "/opt/application" where the archive with the application is downloaded and unpacked into a directory where the short derivative of the HASH commit (8 characters) is used as the name. And a symbolic link is created to this directory. It is necessary to store only the 3 latest versions of the …
Continue reading " Ansible – Store N recent directories and artifacts"
For example, there is an instance on which Python of the 2nd and 3rd versions is installed, but the default is 2nd, and in order not to change the default version and start the Playbook using Python3, you can use the following command: You can also specify the interpreter in the inventory file: …
Continue reading "Ansible – Launch Playbook with a specific version of Python"
In order to create a file from the template and immediately save it as "Pretty JSON", you can use the "copy" module with the "content" key. For example, save the template "config.j2" as the file "/app/config.json" Playbook:
When trying to get a value from AWS SSM, Ansible Playbook using Python3 as an interpreter generates the following error: fatal: [localhost-py3]: FAILED! => {"changed": false, "msg": "AnsibleError: An unhandled exception occurred while templating '{{ lookup('aws_ssm', 'server_listeners', decrypt=false, region=’eu-west-1′) }}'. Error was a <class 'ansible.errors.AnsibleError'>, original message: An unhandled exception occurred while running the lookup …
Continue reading "FIX ERROR – Ansible AWS SSM: AnsibleError: An unhandled exception occurred while templating"
An example of how to get the IP address of another host from the "hosts" file by performing a task on another host. server1 – our Playbook will be executed on it server2 – we need its IP address in the Playbook hosts: In order to get the IP address, we will …
Continue reading "Ansible – Get the IP address of another host from the hosts file"
There is a "hosts" file in which there is a group of "db". These are database instances that play a different role. The goal is to add the role type to the "hosts" file, so that later we can use this value in a loop that will be executed on a completely different host, …
Continue reading "Ansible – Use values in a loop from hosts file on another host"
There is a "hosts" file in which in the "db" group there are N number of hosts, you need to automatically set a variable in the playbook equal to the number of hosts in a particular group hosts example.yaml
The following example was taken as a Playbook. This Playbook runs on the "docker" host group, installs the necessary packages for Docker, adds the Docker repository, installs Docker, launches it and adds it to autorun. Also adds the user "artem" to the group "docker" docker.yaml Apply Playbook:
A simple example of installing Ansible and adding a host. Install Ansible: RedHat systems: Deb systems: Generate an SSH key if it is not on the instance with Ansible: Add the public key to the host, which we will manage: Add the host to the list: And insert the following …
Continue reading " Ansible – Install"