How to generate a Self Signed OpenSSL certificate with Ansible playbooks? private key file does not exist

I am showing my task schema — – name: Ensure directory exists for local self-signed TLS certs. file: path: "{{ certificate_dir }}/{{ server_hostname }}" state: directory – name: Generate an OpenSSL private key. community.crypto.x509_certificate: path: "{{ certificate_dir }}/{{ server_hostname }}/privkey.pem" privatekey_path: "{{ certificate_dir }}/{{ server_hostname }}/privkey.pem" provider: selfsigned When I run playbook I got TASK… Read More How to generate a Self Signed OpenSSL certificate with Ansible playbooks? private key file does not exist

How to override ansible.cfg variable from a subprocess.call from a python script?

When I run the following command from the command line ANSIBLE_DISPLAY_OK_HOSTS=true ansible-playbook -i my_inventory.yaml myplaybook.yaml –tag my_tag then everything works fine, however if I try to do so from a python script using subprocess.call, it fails with "No such file or directory: ‘ANSIBLE_DISPLAY_OK_HOSTS=true’ What is the difference and how to fix it please?? From within… Read More How to override ansible.cfg variable from a subprocess.call from a python script?

Looping on a dictionary with Ansible

I’m trying to create a loop that pulls data from a dictionary using Ansible and create resources (e.g. Group), based on https://docs.ansible.com/ansible/2.9/plugins/lookup/dict.html # main.yaml – name: ‘Linux | Adding groups’ ansible.builtin.group: name: "{{ item.key }}" state: "{{ item.value.state }}" gid: "{{ item.value.gid }}" system: False loop: "{{ lookup(‘dict’, groups) }}" # vars.yaml groups: my_group: state:… Read More Looping on a dictionary with Ansible

Ansible does not expand newline and linefeed characters in verbose SSH output

When debugging an Ansible playbook, I occasionally need to use verbose mode to debug the connection itself, like in this call: ansible-playbook -vvvv -i inventories/whatever playbook_under_test.yml This will, among the debug info from Ansible itself, also output everything that SSH -vvvv would print. However, on the terminal, all newlines and linefeeds from this SSH debug… Read More Ansible does not expand newline and linefeed characters in verbose SSH output

How to manipulate list variable in Jinja2 template?

I’ve created a role which stores the unreachable hosts in a variable: – block: – set_fact: unreachable_hosts: "{{ ansible_play_hosts_all|difference(ansible_play_hosts) }}" – debug: var: unreachable_hosts run_once: true Depending on the amount of unreachable hosts this returns something like this: "unreachable_hosts": [ "server001", "server003" ] In another role I’m creating an HTML file with Jinja2 template. In… Read More How to manipulate list variable in Jinja2 template?

Ansible Simulate "Press Enter" for shell script

I am trying to run this script: /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh When I run it without Ansible I get this: This script will enable the PostgreSQL APT repository on apt.postgresql.org on your system. The distribution codename used will be focal-pgdg. Press Enter to continue, or Ctrl-C to abort. I tried this and some other variations on this. -… Read More Ansible Simulate "Press Enter" for shell script