Difference between revisions of "Ansible Conditions"

From rbachwiki
Jump to navigation Jump to search
(Created page with " = Ansible Menu= Category:Ansible")
 
Line 1: Line 1:
=Conditions=
==When==


<pre>
---
- name: Install Apache WebServer
  hosts: localhost
 
  tasks:
    - name: Install Apache on Ubuntu Server
      apt-get:
        name: apache2
        state: present
      when: ansible_os_family == “Ubuntu“


- name: Install Apache on CentOS  Server
  yum:
    name: httpd
    state: present
  when: ansible_os_family == "RedHat"
</pre>
<code>ansible_os_family</code> is a built in variable
''' you can get a list of all ansible built in variables by running'''
ansible localhost -m setup


=[[Ansible| Ansible Menu]]=
=[[Ansible| Ansible Menu]]=
[[Category:Ansible]]
[[Category:Ansible]]

Revision as of 18:14, 14 July 2022

Conditions

When

---
- name: Install Apache WebServer
  hosts: localhost
  
  tasks:
    - name: Install Apache on Ubuntu Server
      apt-get:
        name: apache2
        state: present
      when: ansible_os_family == “Ubuntu“

- name: Install Apache on CentOS  Server
  yum:
    name: httpd
    state: present
  when: ansible_os_family == "RedHat"

ansible_os_family is a built in variable you can get a list of all ansible built in variables by running

ansible localhost -m setup

Ansible Menu