Skip to main content

Questions tagged [ansible-playbook]

Ansible playbooks are how ansible code is shared and reused.

Filter by
Sorted by
Tagged with
49 votes
3 answers
107k views

Is there a way to check that a dictionary key is not defined in ansible task?

So in my code I have a task: - name: cool task shell: 'touch iamnotcool.txt' when: me.cool is not defined and my vars looks like: --- me: stumped: yes So when I run the task it comes back with ...
Luis F Hernandez's user avatar
41 votes
3 answers
88k views

How to run multiple playbooks in order with Ansible?

I'm working on several Ansible playbooks to spin up a new server instance. There are approximately 15 different playbooks I need to run in a specific order to successfully spin up a server. My ...
nulltek's user avatar
  • 1,311
31 votes
7 answers
91k views

Ansible: How to run one Task Host by Host?

On the play-level, we have serial: 1 to allow us to run the whole play one host at a time. But I haven't found a simple way to do this on a single task. This is especially relevant, if the task in ...
Elrond's user avatar
  • 606
27 votes
4 answers
72k views

Ansible: Is it possible to "cat file" and export it's output to screen while playing a playbook and not as debug?

I wrote a playbook which installs and configures Google Authenticator per user. I want the last step of the playbook to cat the google_authenticator configuration file. Using the "debug" module I am ...
Itai Ganot's user avatar
  • 10.9k
21 votes
6 answers
51k views

How to destroy/delete/unset a variable value in Ansible?

Is there a way to destroy the variable in Ansible? Actually, I have a {{version}} variable being used in my all roles for respective packages. When I run multiple roles, the version value of one role ...
MMA's user avatar
  • 395
19 votes
1 answer
51k views

In ansible, how do I specify an exclusion set of hosts in a playbook?

With command line patterns, you can specify patterns like "all,!ntpservers" but I can't figure out how to specify this in a playbook. I'm regularly running into cases where I have to install a client ...
Robert Rapplean's user avatar
18 votes
2 answers
76k views

Ansible conditionals - Wildcard match string

I have the following conditional in an Ansible task: when: ec2_tag_Name == 'testhost01' It works fine, however I would like to match a wildcard on the ec2_tag_Name field. So something like this ...
emmdee's user avatar
  • 2,307
18 votes
1 answer
10k views

The value True (type bool) in a string field was converted to u'True' (type string)

I'm trying to follow parameters/examples, yet running into following WARNING message while executing Ansible'playbook: TASK [apt (pre)] ****************************************************************...
alexus's user avatar
  • 13.5k
17 votes
3 answers
81k views

ansible-playbook --limit more than one host?

For various reasons/limitations I cannot make new groups in the inventory file and need to use --limit/-l to specify the hosts. I was told to do something like: ansible-playbook -i /path/to/my/...
ConstantFun's user avatar
17 votes
1 answer
16k views

Why is ansible notify not working?

I'm learning ansible and wrote simple playbook, but I don't understand or what I'm doing wrong that handler not working! Please, help me. My playbook: - hosts: HA gather_facts: False tasks: -...
amkgi's user avatar
  • 323
15 votes
2 answers
12k views

Force Ansible to log off to refresh user groups

I'm setting up a server with Ansible and Docker. I'm currently learning both technologies, so please bear with me if I'm being overly stupid here. In order to run run Docker commands, the user has to ...
MadMonkey's user avatar
  • 305
11 votes
3 answers
34k views

Rollback the changes in Ansible

Is there any method to rollback the changes in Ansible? Suppose my play book contains different plays like create 5 users,install 3 rpms, start the services. If I want to rollback a certain play how ...
KKE's user avatar
  • 135
11 votes
3 answers
21k views

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 ...
emmdee's user avatar
  • 2,307
11 votes
1 answer
64k views

Converting string to integer in Ansible Playbook

I am getting a count from powershell command and registering it on variable. I have to use that count in when condition. I have changed it to int before using it in when condition too. Still that task ...
saffron's user avatar
  • 153
11 votes
2 answers
55k views

Why does an `"[Errno 2] No such file or directory", "rc"` issue occur when Ansible is executed remotely?

Running: - name: get vhosts command: rabbitmqctl list_vhosts register: vhosts changed_when: false by issuing sudo ansible-playbook file.yml results in: TASK [030.sensu : get vhosts] ********...
030's user avatar
  • 6,015
11 votes
1 answer
2k views

What is reasonable performance for a simple Ansible playbook against ~100 hosts?

We are starting to look at Ansible to replace an old cfengine2 installation. I have a simple playbook that: copies a sudoers file copies a templated resolv.conf (fed with group_vars and host_vars ...
user53814's user avatar
  • 396
9 votes
1 answer
21k views

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 ...
doh-nutz's user avatar
  • 227
9 votes
3 answers
32k views

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:...
dejanualex's user avatar
9 votes
1 answer
25k views

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 > /...
Gerald Schneider's user avatar
8 votes
1 answer
73k views

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 ...
AnujAroshA's user avatar
8 votes
4 answers
18k views

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 ...
Prince Joseph's user avatar
8 votes
3 answers
15k views

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 ...
030's user avatar
  • 6,015
8 votes
5 answers
63k views

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:...
trikelef's user avatar
  • 528
7 votes
2 answers
18k views

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: - ...
Mat's user avatar
  • 1,913
7 votes
2 answers
598 views

Ansible performance issues on a huge group

So, I have this host group, which consist of 35k VMs. Aaaand I need to run a playbook over it. If it does matter - playbook is just a call for community role for installing node_exporter. But I'm ...
Anatolii Tk's user avatar
7 votes
5 answers
3k views

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!"...
Phenyl's user avatar
  • 193
7 votes
1 answer
12k views

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 ...
trikelef's user avatar
  • 528
7 votes
1 answer
12k views

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 ...
Luis F Hernandez's user avatar
6 votes
4 answers
24k views

Ansible: "You need to install 'jmespath' prior to running json_query filter", but it is installed

I am using Ansible on top of Python3 and Enterprise Linux 8 (Rocky Linux 8). When I try to use json_query, I am getting the following error: fatal: [ansible]: FAILED! => {"msg": "You ...
norinori's user avatar
  • 131
6 votes
2 answers
1k views

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 ...
Bastian Voigt's user avatar
6 votes
1 answer
17k views

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 }}" ...
Wanexa's user avatar
  • 71
5 votes
1 answer
11k views

Creating an instance service file using an ansible template

I have been using ansible for a while to install and configure several services, but this is the first time I am trying to set up a service that can have multiple instances running at the same time. I'...
user3270760's user avatar
5 votes
1 answer
14k views

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), ...
Wolske's user avatar
  • 53
5 votes
2 answers
18k views

Iterating through nested list / dictionary using Jinja2 templates

I'm trying to dynamically configure multiple NFS servers in my system by generating their /etc/exports files using Ansible. I'm hoping to be able to do this with a jinja2 template. It's the jinja2 ...
dutsnekcirf's user avatar
5 votes
2 answers
3k views

Ansible: become twice

I'd like to run ansible such that: remote user is 'normal' user ... who becomes root via sudo to run a bunch of tasks ... who 'becomes postgres user via su - postgres, from root, to create a ...
badbishop's user avatar
  • 928
5 votes
1 answer
8k views

Running an Ansible command in multiple docker containers

I need to run a command against multiple running containers. For example, let's say my app needs to run a data structure update against a database after receiving code updates. To do this, we want to ...
DMCoding's user avatar
  • 492
5 votes
1 answer
38k views

Ansible backslash escaping in playbooks

How can you properly escape backslash in ansible playbooks? I am trying to do a search and replace for the backslash in the password, but I am not even able to add backslash as a string in the ...
Mircea Vutcovici's user avatar
5 votes
2 answers
1k views

How to manage a modified copy of a file?

Following this answer, I want to make a copy of OpenSSL's configuration, with a specific set of changes. The original file is out of my control, so I can't make it a template. At the moment I have: -...
Petr's user avatar
  • 635
4 votes
2 answers
10k views

How to split an ansible local_action in multiple lines

I have a local_action the I would like to split in multiple lines. - name: Find geographical region of this server local_action: uri url=http://locator/studio/{{ ansible_default_ipv4.address}} ...
Mircea Vutcovici's user avatar
4 votes
2 answers
25k views

Run Ansible task conditionally and fail if condition is not met

I am very new to Ansible and having an issue. I want to run the module only if a condition is met but if the condition is failed, it should fail the task and report to user. Currently what I have done,...
Coder's user avatar
  • 83
4 votes
2 answers
2k views

Ansible command ignore creates

I use command module with creates on an ansible 2.9 role. However, sometimes I need to ignore the creates arg and re-run the command multiple times. Is there any way I can override the default ...
trikelef's user avatar
  • 528
4 votes
1 answer
24k views

How can i check software version with Ansible?

I have three linux servers and i created the ansible inventory file: [web] 192.168.0.155 192.168.0.165 192.168.0.175 And i have playbook.yml: --- - hosts: web tasks: - name: Check drinks ...
Ivan Denisovich's user avatar
4 votes
1 answer
843 views

Can I overwrite, what `diff` means for a task?

With some file types, simple unified diff is not very helpful. One obvious example is binary files, but even certain ostensibly textual ones -- such as SSL-certificates (.pem) -- fall into this ...
Mikhail T.'s user avatar
  • 2,411
4 votes
1 answer
16k views

How to perform an action when a file is not present with Ansible?

I want to make a list of servers that don't have a particular file. I made the following Ansible playbook: - name: "If file not in /apps" hosts: all tasks: - name: Find apps ...
yes's user avatar
  • 51
4 votes
2 answers
20k views

How to loop an array variable in Ansible

I have below task and I am failing to add the loop for the array variable. ShopID is defined as an array inside group_vars. My aim is to call each variable one by one. - name: Create directories with ...
Roushan Jha's user avatar
4 votes
1 answer
7k views

Add Static Route on Linux with Ansible

I would like to know if there's a module I can use to manage static routes on a Linux device (Ubuntu 18.04) I have found this question: Add static route with Ansible but this was asked almost 4 ...
Owensteam's user avatar
  • 120
4 votes
2 answers
5k views

How do I report an Ansible command/shell task as changed in check mode?

In my Ansible playbook I have this: - name: "A: Check to see if we need to run task B" [... implementation omitted, not relevant ...] register: task_a_result check_mode: no # even run in check ...
gertvdijk's user avatar
  • 3,624
4 votes
1 answer
6k views

Returning python script value and using that in the ansible task

I am new to Ansible and a bit stuck. I have a python script that returns true or false. I run this python script via ansible task. I am trying to debug the value returned by running the py script. ...
Coder's user avatar
  • 83
4 votes
1 answer
2k views

How to notify a remote service using Ansible?

In order to let checks appear in Uchiwa when a new sensu-client is added, the sensu-server and sensu-api need to be restarted. At the moment there are 5 clients and one server. Everytime a new sensu-...
030's user avatar
  • 6,015
3 votes
1 answer
7k views

List tags that exists in a playbook

I have a play that runs one or more roles. I would like to list available tags without parsing all the code. I am indeed experimenting some difficulties in remembering all the tags I put during ...
MUY Belgium's user avatar

1
2 3 4 5
10