ansible

How to output loop.index in jinja

How to output loop.index in jinja Question: I want to be able to output the loop.index iteration to my template , i am using ansible and i have template file.j2 and inventory file have the below group [all_servers] app01 ansible_host=10.10.1.100 app02 ansible_host=10.10.1.102 app03 ansible_host=10.10.1.103 app04 ansible_host=10.10.1.104 app05 ansible_host=10.10.1.105 app06 ansible_host=10.10.1.106 I have jinja file inside …

Total answers: 1

Ansible – How to get the value of a variable that's inside a List of Dicts?

Ansible – How to get the value of a variable that's inside a List of Dicts? Question: I need to get the value of the $HOME path of newly created users with the module ansible.builtin.user. Here’s the playbook: — – name: Create users vars: users: user1: passwd: uid: ‘1111’ comment: ‘Test User’ shell: ‘/bin/zsh’ user2: …

Total answers: 2

Persist environment variables for future ansible tasks

Persist environment variables for future ansible tasks Question: i´m triying to set in my localhost via a play env vars for future tasks/playbooks in the same localhost. – name: Environment_vars hosts: 127.0.0.1 connection: local vars: env_vars: /opt/env_vars.yml env_path: ~/.bashrc tasks: – name: put into .bashrc lineinfile: path: "{{env_path}}" state: present regexp: "^{{ item.key }}=" line: …

Total answers: 1

Not able to execute python3.8 code with ansible

Not able to execute python3.8 code with ansible Question: I have a playbook: — – hosts: all gather_facts: true tasks: – name: test shell: cmd: python /tmp/test.py chdir: /tmp/ async: 150 poll: 5 become: true register: test – debug: msg={{test}} Below is the host file for me: xx.xxx.xxx.xx ansible_ssh_user=xxx ansible_ssh_pass=xxxxxxxxxxxxxxx ansible_sudo_pass=xxxxxxxxxxxxxxx ansible_ssh_common_args=’-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no’ …

Total answers: 1

Iterating through list of dictionaries within a dictionary – Jinja2 and Ansible

Iterating through list of dictionaries within a dictionary – Jinja2 and Ansible Question: I am trying to extract the "host" and "port" value from the following JSON output with Jinja2: "net_neighbors": { "Ethernet0/0": [ { "host": "Switch", "platform": "Linux Unix", "port": "Ethernet0/2" } ], "Ethernet0/1": [ { "host": "DAL-R", "platform": "Linux Unix", "port": "Ethernet0/1" } …

Total answers: 1

Passing a number to a python script

Passing a number to a python script Question: I am working in Linux using Ansible. I am trying to run a script from a playbook, but I need to pass the script a few arguments: a string and 2 numbers. The first number is the number of times I need to retry to run the …

Total answers: 3

Can't correctly dump Ansible vault into yaml with Python

Can't correctly dump Ansible vault into yaml with Python Question: I have a python dictionary with an Ansible vault as a value. I can’t seem to be able to correctly dump it into a yaml output with the correct formatting. I’m using the ansible-vault package to generate the encrypted data as follows: from ansible_vault import …

Total answers: 1

changed_when: in Ansible

changed_when: in Ansible Question: I’m having trouble setting up the changed_when condition on a specific task on my playbook. I used to use ignore_errors: true in the past, using the git module: – name: Checkout in client folder ansible.builtin.git: repo: "{{ item.value.dev_repo | default(‘git@*****:***/****.git’) }}" key_file: /tmp/oci_odoo.rsa accept_hostkey: true dest: "/opt/odoo/odoo_{{ item.key }}/addons" version: "{{ …

Total answers: 1

Cannot install ansible-pylibssh on macOS

Cannot install ansible-pylibssh on macOS Question: I’m trying to install ansible-pylibssh on an Apple Silicon based Mac. ansible is already installed. When running pip3 install ansible-pylibssh I get the following error: pip3 install –user ansible-pylibssh  1 ✘  took 3s   at 00:36:15  Collecting ansible-pylibssh Using cached ansible-pylibssh-1.0.0.tar.gz (97 kB) Installing build …

Total answers: 3

Issue with lookup('dig') not finding 'dnspython'

Issue with lookup('dig') not finding 'dnspython' Question: On a Red Hat 8.3 machine I try to use this ansible code: – debug: msg: "{{ lookup(‘dig’, ‘localhost’) }}" But I get an error: TASK***************************************** fatal: [demo.example.com]: FAILED! => {"msg": "An unhandled exception occurred while running the lookup plugin ‘dig’. Error was a <class ‘ansible.errors.AnsibleError’>, original message: …

Total answers: 1