Questions tagged [ansible-playbook]

468 questions
5
votes
2 answers

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 PostgreSQL database. This is typical procedure for…
badbishop
  • 928
  • 4
  • 12
  • 21
5
votes
1 answer

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'm using a template for the service file,…
user3270760
  • 163
  • 2
  • 2
  • 8
5
votes
1 answer

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 run docker build -t latest, then…
DMCoding
  • 492
  • 5
  • 11
5
votes
1 answer

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 regex_replace jinja2 filter. I am using ansible version…
Mircea Vutcovici
  • 17,619
  • 4
  • 56
  • 83
5
votes
2 answers

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 template that I can't figure out based on my…
dutsnekcirf
  • 249
  • 2
  • 4
  • 16
5
votes
2 answers

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: - name: Make a copy copy: src:…
Petr
  • 581
  • 1
  • 5
  • 16
4
votes
1 answer

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 years ago and ansible has moved forward since then so…
Owensteam
  • 120
  • 2
  • 10
4
votes
2 answers

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 mode changed_when: no # this only reads/checks…
gertvdijk
  • 3,504
  • 4
  • 30
  • 46
4
votes
1 answer

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 category too. So, can a task specify its own method of…
Mikhail T.
  • 2,338
  • 1
  • 24
  • 55
4
votes
2 answers

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}} method=GET return_content=yes…
Mircea Vutcovici
  • 17,619
  • 4
  • 56
  • 83
4
votes
1 answer

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-client is added using ansible the checks do not…
030
  • 5,901
  • 13
  • 68
  • 110
4
votes
1 answer

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 versions shell: "python3.4 {{ item.sw_path }} -v" …
4
votes
2 answers

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 required permission file: path: "{{…
Roushan Jha
  • 55
  • 1
  • 1
  • 5
4
votes
2 answers

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 behaviour and force the execution of the tasks?
trikelef
  • 518
  • 1
  • 7
  • 26
4
votes
2 answers

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, it will only skip it rather than failing…
Coder
  • 83
  • 1
  • 2
  • 5
1 2
3
31 32