How to use conditions in Ansible-Playbook

0 votes

Hi Guys,

I have one playbook. I have written some codes inside this playbook. How can I use conditions in my Playbook? Can anyone help me?

Aug 20, 2020 in Ansible by akhtar
• 38,260 points
1,503 views

1 answer to this question.

0 votes

Hi@akhtar,

Traditional programming language usually uses the if-else statement when more than one outcome is expected. In Ansible when statement is used instead to determine the outcome of a variable. So instead of using the if-else statement, you can use when statement. The syntax is as given below.

- name: install Apache Web-Server
  hosts: all
  tasks:
    - name: Install Apache on CentOS  Server
      yum: name=httpd  state=present
      become: yes
      when: ansible_os_family == "RedHat"
answered Aug 20, 2020 by MD
• 95,460 points

Related Questions In Ansible

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How to overwrite the content of a file in remote systems using Ansible playbook?

Hi@akhtar, You can find one argument in the ...READ MORE

answered Aug 2, 2020 in Ansible by MD
• 95,460 points
14,486 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,063 views
+2 votes
1 answer
0 votes
1 answer

How to use an URL in Ansible Playbook?

Hi@akhtar, You can use the get_url module in ...READ MORE

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

How to use loop in Ansible playbook?

Hi@akhtar, Sometimes you want to repeat a task ...READ MORE

answered Sep 1, 2020 in Ansible by MD
• 95,460 points
1,140 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