Questions tagged [ansible-playbook]

Ansible playbooks are how ansible code is shared and reused.

477 questions
52
votes
3 answers

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 the following error: {"failed": true, "msg":…
42
votes
3 answers

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 initial thought was to write a shell script that…
nulltek
  • 1,331
32
votes
7 answers

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 question doesn't perform proper locking (for…
Elrond
  • 618
27
votes
4 answers

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 able to get the data to be displayed on screen but…
Itai Ganot
  • 10,976
24
votes
7 answers

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 is passed to another - this is due to for some…
MMA
  • 425
21
votes
2 answers

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 when: ec2_tag_Name == 'testhost*' The goal is to…
emmdee
  • 2,397
  • 12
  • 43
  • 65
21
votes
1 answer

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 on all machines except the server.
21
votes
3 answers

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/inventory/file.ini -l server.1.com server.2.com…
18
votes
1 answer

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)] ******************************************************************************************** [WARNING]: The value…
alexus
  • 13,667
18
votes
1 answer

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: - name: Installs pacemaker yum:…
amkgi
  • 333
16
votes
2 answers

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 be in the docker user group. So I'm doing this: -…
13
votes
2 answers

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 ( mail notification) is getting skipped,…
saffron
  • 173
13
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,397
  • 12
  • 43
  • 65
12
votes
3 answers

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 can I do. Is there any possibility that we can…
KKE
  • 145
11
votes
1 answer

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 data) checks a couple of services are running checks…
user53814
  • 396
  • 1
  • 9
1
2 3
31 32