Questions tagged [ansible-playbook]
468 questions
3
votes
2 answers
How to use a AWS EC2 Iam role with Ansible
I am running Ansible on an EC2 instance with an assigned Iam role.
I am running this playbook:
$ cat s3.yaml
---
- hosts: localhost
remote_user: ec2-user
tasks:
- name: download ec2.py from s3
s3:
bucket: mybucket
…

M. Glatki
- 1,964
- 1
- 17
- 33
3
votes
1 answer
How to display raw messages in Ansible?
I have the following playbook:
---
- name: Find sudo mit PPID 1
hosts: solaris
become: true
tasks:
- shell: "pgrep -P1 -x sudo | xargs -n1 ptree"
register: result
- debug: var=result.stdout_lines
The command ansible-playbook…

ceving
- 534
- 4
- 26
3
votes
1 answer
How to handle network changes and restart with Ansible?
I'm currently developping a network configuration role used by Ansible to customize our fresh new virtual machine that came from our Debian 11 template.
The following role changes from DHCP to static interface configuration and then restart the…

motorbass
- 303
- 2
- 12
3
votes
1 answer
How to debug Ansible dict for failed ports with wait_for module?
I have written the below playbook to fetch the failed port status.
- name: Check port status
wait_for:
host: 127.0.0.1
port: "{{ item }}"
timeout: 2
state: started
ignore_errors: yes
with_items:
- 80
-…

Kamal
- 31
- 2
3
votes
1 answer
Ansible 2.9.21: unwanted escape char “\” is added in shell command
In my playbook the following line should return 1, and if it returns >1, the play should stop:
shell: ls -l /opt/tomcat/|grep "[ ]\+{{ newTomcatVer }}$"; echo $?
My play did indeed fail with this error:
"msg": "There is more than one…

kamokoba
- 133
- 1
- 5
3
votes
2 answers
Using variable lists in ansible returns undefined variable
Here is my variable list file vars/blah.yml:
---
stuff:
- stuff1: bill
stuff2: sue
I just trying to get the values of the variable stuff.
Here's my playbook:
hosts: all
become: yes
vars_files:
- vars/blah.yml
tasks:
- name: test
…

user1712037
- 31
- 1
- 3
3
votes
3 answers
Using if else statement inside shell module in ansible playbook
I am trying to run if else statement inside shell module in ansible playbook but looks like my else statement is not executing in any case.
- name: verify application/database processes are not running
shell: if ps -eaf | egrep…

user600994
- 31
- 1
- 2
3
votes
1 answer
Ansible, with_nested, How to asign dynamic variables in loop
I'm trying to iterate through the number of entries dynamically in an array and use the output as an index.
Pretty sure I'm doing something wrong.
How can I assign a variable to the sequence end that represents the count of my current…

Malan
- 31
- 1
- 6
3
votes
1 answer
Running one task from role
I tried to run playbook with role and only few task from it.
F.e.
I have playbook
# setup.yaml
- hosts: all
tasks:
- include_role:
name: system
tags: setup
and role "system" with tasks:
# roles/system/tasks/main.yaml
- name:…

Anaoliy Tk
- 58
- 1
- 6
3
votes
2 answers
How to pass a group value in inventory file to jinja2 template file in ansible
I have an inventory file named hospital.inventory and it contains following group with a single value.
[dockerSwarmManager]
hp2-3.mydomain.com
Then I have a file name security.json.j2 inside the folder call templates. In there I want to refer above…

AnujAroshA
- 213
- 1
- 3
- 7
2
votes
2 answers
ansible task with tag 'never' inside role executed when the role is executed using another tag
I have a playbook which has three roles netdata, netdata_master, netdata_slaves:
---
- hosts: netdata_master
become: yes
roles:
- role: netdata
- role: netdata_master
tags: ['netdata_master']
- hosts: netdata_slaves
become: yes
…

Yashar
- 151
- 4
2
votes
1 answer
Ansible gives me an error during execution of some playbooks
I use Ansible 2.9.2 on Ubuntu Server 18.04 + Python 3.6.9. Here is a simple Ansible project: https://github.com/770715/ansible.git
If I run:
ansible-playbook -i aws_ec2.yml add-ssh-keys.yml
it works just fine but when I try to run:
ansible-playbook…

Jacek
- 53
- 2
- 2
- 4
2
votes
2 answers
ansible delegate_to doesn't use inventory host?
I'm attempting to use ansible synchronize to copy files between two remotes.
My playbook looks like:
- hosts: newserver
tasks:
- name: Copy images from old to new
synchronize:
src: /var/www/production/
dest:…

GaryBishop
- 123
- 1
- 5
2
votes
1 answer
Ansible - Proper method for handling roles, tasks, dependencies?
Ansible - Proper method for handling roles, tasks, dependencies ?
Related to How to keep ansible role from running multiple times when listed as a dependency?
This is a long post/question. TL;DR - what's the right way to setup tagging of roles and…

Halfwalker
- 21
- 1
- 3
2
votes
1 answer
Ansible Playbook Task Gets Skipped
I have 3 aws ec2 instances, 2 are ubuntu and 1 amazon linux 2. I have configured the master slave setup and works fine.
Master Instance:
NAME="Ubuntu"
VERSION="18.04.3 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.3…

Guest
- 21
- 1
- 2