Can I use something like if statement to check for conditions in my playbook

0 votes
I am very new to ansible and don't really know how to write playbooks. Can I have a simple if-else construct in my playbook?

Or is there a specific module for this purpose?
Feb 11, 2019 in Ansible by Kashish
4,270 views

1 answer to this question.

0 votes

Hey @Kashish, you could use something like this:

- name: Check certs exist
  stat: path=/etc/letsencrypt/live/{{ rootDomain }}/fullchain.pem
  register: st

- include: ./_common/check-certs-renewable.yaml
  when: st.stat.exists

- include: ./_common/create-certs.yaml
  when: not st.stat.exists
answered Feb 11, 2019 by Kyra

Related Questions In Ansible

0 votes
1 answer

Ansible playbook to check if http support for apt is installed

Hi @Hannah, this ansible task should do ...READ MORE

answered Nov 25, 2019 in Ansible by Aria
1,064 views
0 votes
1 answer

How to use conditions in Ansible-Playbook?

Hi@akhtar, Traditional programming language usually uses the if-else ...READ MORE

answered Aug 20, 2020 in Ansible by MD
• 95,460 points
1,504 views
0 votes
1 answer

How do i set multiple authorized keys to my ansible playbook?

Try this: - name: Set up multiple authorized ...READ MORE

answered Feb 12, 2019 in Ansible by John
1,483 views
0 votes
1 answer

Playbook to get all the container's ARN's in my AWS ECS cluster

Hey @haseeb, you could try something like ...READ MORE

answered Apr 9, 2019 in Ansible by Anshul
1,004 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,064 views
+2 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Is it possible to run an Ansible Playbook in python script?

Hey @Cerci, Of course its possible. You ...READ MORE

answered Jan 17, 2019 in Ansible by Nicolas
15,742 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP