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 in Ansible by Kashish
17 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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 by Kyra

Related Questions In Ansible

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 11 in Ansible by John
27 views
0 votes
1 answer
0 votes
1 answer

How do I execute a shell script and then use the result in ansible

This can work out for you: - name: ...READ MORE

answered Apr 11, 2018 in Ansible by shubham
• 6,480 points
223 views
0 votes
1 answer

Running to plays in one playbook

The inventory file is loaded before a ...READ MORE

answered Jun 25, 2018 in Ansible by ajs3033
• 7,000 points
21 views
+13 votes
2 answers
0 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 in Ansible by Nicolas
577 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.