Questions tagged [ansible-playbook]
468 questions
9
votes
1 answer
Register ansible variable in multiple tasks
I'm using the following tasks in an ansible script that installs updates on various servers. These tasks are for CentOS machines:
- name: Check for outstanding reboot
shell: needs-restarting > /dev/null || echo Reboot required
when:…

Gerald Schneider
- 23,274
- 8
- 57
- 89
9
votes
1 answer
ansible run global variable
I want to create a cluster of servers, using ansible.
In one main-playbook, I include some sub-playbooks.
- include: playbook_commandserver.yml
- include: playbook_agent.yml
In the playbook_commandserver.yml, I create the command-server (on…

doh-nutz
- 227
- 1
- 3
- 9
9
votes
3 answers
Use Ansible include_tasks with tags on the sub-tasks
Ansible 2.8.1
In my playbook tasks/ dir:
main.yml
dev.yml
In main.yml I have a block like this:
- include_tasks: dev.yml
when: ec2_tag_env == 'dev'
It works fine
However, if I try to call a specific task within dev.yml using a tag. It won't…

emmdee
- 2,187
- 12
- 36
- 60
8
votes
5 answers
Ansible task write to local log file
Using Ansible I would like to be able to write the sysout of a task running a command to a local(i.e. on the managed server) log file.
For the moment I can only do this using a task like this:
- name: Run my command
shell: …

trikelef
- 518
- 1
- 7
- 26
8
votes
3 answers
What is the correct syntax of defining role dependencies in the meta/main.yml in Ansible?
meta/main.yml
dependencies:
- { role: 030.sensu-install }
results in:
[DEPRECATION WARNING]: The comma separated role spec format, use the
yaml/explicit format instead..
This feature will be removed in a future release.
Deprecation warnings can…

030
- 5,901
- 13
- 68
- 110
8
votes
1 answer
Extracting part of the string using Ansible regex_search and save the output as a variable
I'm having a content like below inside a file.
dataDir=/var/lib/zookeeper
4lw.commands.whitelist=mntr,conf,ruok,stat
syncLimit=2
I wanted to read the value for dataDir using Ansible and set it to a variable. I have written following code but…

AnujAroshA
- 213
- 1
- 3
- 7
8
votes
2 answers
ansible display file content to stdout
I'm using ansible 2.9.3 and I'm having trouble trying to display the content of a file from the target machine, this is my playbook :
-
name: Display content of resolv.conf
hosts: jenkins
tasks:
- name: Display resolv.conf contents
…

dejanualex
- 185
- 1
- 1
- 7
7
votes
1 answer
Is there any way to see the group_vars, host_vars, etc. available to a host in ansible?
So I just started a new company, and while familiarizing myself with the ansible repository, I was wondering if there's any way to see the variables that come from group_vars, host_vars and all that together in one place, it's non-trivial to gather…

Luis F Hernandez
- 683
- 1
- 7
- 9
7
votes
4 answers
How to do mysql_secure_installation via ansible playbook?
I managed to install Apache Mysql/Mariadb and PHP using playbook. How can I do mysql_secure_installation using ansible?
I am a beginner in Ansible. I want to set a new password to MySQL server and complete all security questions via playbook.

Prince Joseph
- 71
- 1
- 1
- 3
6
votes
1 answer
Ansible same host on different groups with group_vars
I have an Ansible inventory like the following:
[group1]
host1.mydomain
[maingroup:children]
group1
[group2]
host1.mydomain
I need to declare the same host on different groups since in this host there are two similar services collocated.
In order…

trikelef
- 518
- 1
- 7
- 26
6
votes
1 answer
Ansible how to get output as variable without brackets and u
I have the result of a query from ansible and I tried to use the result as a variable
My playbook is like this
- name: Query
oracle_sql:
username: "{{ user }}"
password: "{{ password }}"
service_name: "{{ service_name }}"
sql:…

Wanexa
- 71
- 1
- 1
- 2
6
votes
2 answers
Best way to install security updates on amazon ECS instances
We're using Ansible to roll out security updates on all our EC2 instances which are running stateful services such as databases, search engines etc. This works fine.
I'm wondering what is the best way to make security updates on the ECS instances…

Bastian Voigt
- 165
- 9
6
votes
5 answers
Print Ansible header before executing a long running task
Context
I have an Ansible playbook that includes a very long task, up to one hour.
Very simplified, it looks like:
- hosts: localhost
tasks:
- name: Short task
debug:
msg: "I'm quick!"
- name: Long task
shell: "sleep 15s"
When…

Phenyl
- 183
- 7
5
votes
1 answer
Ansible split string on backslash
I'm passing a list of dir/subdirs into a playbook as follows:
dirs=['Web\this','Web\that','Web']
This works fine when I actually do tasks on those directories (win_shell, invoking a build process), but later I need to copy the files and the '\'…

Wolske
- 53
- 1
- 1
- 6
5
votes
2 answers
Tags not applied in Ansible included role
I created a simple Ansible playbook:
---
- hosts: all
tasks:
- name: Install Icinga2 on Windows
include_role:
name: my.icinga2.role
apply:
tags:
- install-icinga2
The role contains this tasks…

Mat
- 1,873
- 7
- 25
- 41