Questions tagged [ansible-playbook]
468 questions
0
votes
2 answers
Best way to create yaml files that have a variable number sections based on host
I am trying to use ansible to deploy configuration files out to hundreds of machines in which different machines will have multiple iterations of specific configuration snippets. Specifically I am using the promtail log parser and different machines…

flyerhawk
- 27
- 3
0
votes
1 answer
ansible registering variable outputs undefined variable
I'm trying to do this playbook for half a day. I'm using stat module to check sha1sum of file and if it is not equal to second file it should replace correct file.
But while registering some variables the output says that variables is undefined
What…

DeviC3
- 3
- 2
0
votes
1 answer
Getting error AnsibleUndefinedVariable: 'facter_ipaddress_eth1' when running ansible playbook
Getting one big error stacktrace of ansible variable not found exception
ansible.errors.AnsibleUndefinedVariable: 'facter_ipaddress_eth1'
while I am runing ansible play book.
the value that gets set here and other…

Ciasto piekarz
- 111
- 1
- 10
0
votes
1 answer
Ansible blockinfile module - insert insert lines of code
I try to insert lines of code (shell script) with Ansible blockinfile module.
name: Customized prompt
blockinfile:
path: /etc/profile.d/customized_prompt.sh
create: yes
block: |
#!/bin/bash
# customized prompt normal user and root
if (( "$(id…

Maxime
- 69
- 7
0
votes
0 answers
Ansible- Define variables based on conditions with if elif else
I have multiple roles as follows : haproxy, java, nginx, tomcat
├── ansible-test-host.yml
├── hapoxy
├── java
├── myplaybook.yml
├── nginx
└── tomcat
Base playbook is : myplaybook.yml and looks like below:
---
- hosts: test-local
connection:…

SAGAR Nair
- 133
- 1
- 8
0
votes
1 answer
ansible AND operation with WHEN is failing when using ansible_facts
Team: I am trying to fail a task when two conditions are not met on a node. ansible_facts['distribution_version'] and ansible_facts['distribution'].
I am passing in two nodes. one node is 20.x ubuntu and other is 18.x.
vars/main.yml
os_distribution:…

AhmFM
- 119
- 5
0
votes
1 answer
Ansible: How force kill process and exit from ansible-playbook if not successful?
I have two bellow tasks as part from my playbook
- name: "Verify httpd.service no running on node {{ ansible_hostname }}"
shell: "ps -ef | grep httpd"
register: _ps_httpd
become: true
- name: stop httpd is exit code eq to 0
…

shlco
- 1
- 2
- 3
0
votes
1 answer
Ansible playbook rebooting the server , wait till reboot complete
I'm facing a issue while executing shell script with ansible playbook.
Issue: I'm losing a connection with remote server because shell script is rebooting the server.
My Ansible playbook
- name: Handle reboot
hosts: all
become: yes
tasks:
…

vik2595
- 1
- 3
0
votes
1 answer
Ansible playbook - defining var based on condition
I want to create a var based on condition so I created the below :
hosts: test
vars: vtarget_backup_folder_in_progress: "{{ "{{ folder }}/{{ target }}/test{{ hostvars['localhost']['tstamp'].stdout }}{{ type }}" if node_type == "master" else "{{…

Sam
- 1
- 1
0
votes
1 answer
How to make Ansible run batch of tasks on Cluster Node's - node by node
I have an ansible playbook which looks roughly like the following.
I need Zero Downtime Upgrade start and Zero Downtime Upgrade completed steps. will run once to put\remove cluser into upgrade mode.
in addition I need all the tasks into Block will…

shlco
- 1
- 2
- 3
0
votes
1 answer
Ansible copy module - how to update file with an existing 'i' attribute?
I have a task in my playbook which should copy some files to a target directoy
The files should have an 'i' flag upon completion, so I set the attributes parameter of the copy like attributes: +i
this works for none existing files existing ones…

vrms
- 287
- 1
- 7
- 17
0
votes
1 answer
Ansible jinja2 template from JSON format provided as extra-vars
I have this jinja2 template:
# {{ ansible_managed }}
{% for vhost in nginx_vhosts %}
{%- if vhost.name == item.name -%}
# redirect www to non-www
server {
listen {{ nginx_port }};
listen [::]:{{ nginx_port }};
port_in_redirect off;
…

Bogdan Stoica
- 403
- 4
- 9
0
votes
1 answer
Hostvar syntax cannot receive extra variable as hostname
I'm is trying to use an extra vars to set the hostname in the "hostvars" variable to get the uuid from other host. But it seems that don't catches the variable's value.
This is the run line:
$ ansible-playbook -i ../Inventory/my_inventory --vault-id…

azk
- 39
- 9
0
votes
1 answer
Ansible - Could not print value of custom fact
This is a playbook part of a role that talks with vmware.
I'm is trying to set a custom fact (target_vm) that receive the virtual machine name.
But when I Print it's value with the debug module it apears to be empty.
It seams that the set_fact is…

azk
- 39
- 9
0
votes
2 answers
Ansible: Pbrun not able to execute
I have the below inventory file
[server]
abc.com
[server:vars]
ansible_user="user1"
ansible_ssh_pass="pwd"
ansible_pbrun_exe="pbrun"
ansible_pbrun_password="pqa"
ansible_pbrun_user="root"
and the playbook file
---
- name: Upgrade Java Version to…

Rajarshi Das
- 113
- 6