Ansible – Template: to_nice_json

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:

FIX ERROR – Ansible AWS SSM: AnsibleError: An unhandled exception occurred while templating

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"

Ansible – Number of hosts per group

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

 Ansible Playbook – Install Docker on CentOS 7

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:

 Ansible – Install

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"