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,170 points
104 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,160 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,160 points
3,121 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 26, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
1,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,160 points
375 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,160 points
151 views