Example – 1 For CENTOS / RHEL
---
- name: Update web servers
hosts: web
vars:
myname: "Rajesh Kumar"
tasks:
- name: Install Apache in centos7
ansible.builtin.yum:
name: httpd
state: latest
when: ( ansible_os_family == "RedHat" and ansible_system == "Linux")
- name: Copy index.html
ansible.builtin.copy:
src: index.html
dest: /var/www/html/index.html
- name: Starting a Apache Server
ansible.builtin.service:
name: httpd
state: started
when:
- ansible_os_family == "RedHat"
- ansible_distribution_major_version == "7"
- ansible_system == "Linux"
- name: My Name is Equals to Rajesh Kumar
debug:
msg: "My Name is Equals to Rajesh Kumar"
when: myname == "Rajesh Kumar"
- name: Ansible print when ubuntu
debug:
msg: "I am ubuntu"
when: ansible_os_family == "Debian"
- name: My Name is not Equals to Rajesh Kumar
debug:
msg: "My Name is not Equals to Rajesh Kumar"
when: myname != "Rajesh Kumar"
Example – 1 For Ubuntu
- name: Update web servers
hosts: web
vars:
myname: "Rajesh Kumar"
tasks:
- name: Install Apache in ubuntu
ansible.builtin.apt:
name: apache2
state: latest
when: ( ansible_os_family == "Debian" and ansible_system == "Linux")
- name: Copy index.html
ansible.builtin.copy:
src: index.html
dest: /var/www/html/index.html
- name: Starting a Apache Server
ansible.builtin.service:
name: apache2
state: started
when:
- ansible_os_family == "Debian"
- ansible_distribution_major_version == "20"
- ansible_system == "Linux"
- name: My Name is Equals to Rajesh Kumar
debug:
msg: "My Name is Equals to Rajesh Kumar"
when: myname == "Rajesh Kumar"
- name: Ansible print when ubuntu
debug:
msg: "I am ubuntu"
when: ansible_os_family == "Debian"
- name: My Name is not Equals to Rajesh Kumar
debug:
msg: "My Name is not Equals to Rajesh Kumar"
when: myname != "Rajesh Kumar"
![loading](https://www.devopsschool.com/blog/wp-content/plugins/youtube-embed-plus/images/gallery-page-loader.gif)
![play](https://www.devopsschool.com/blog/wp-content/plugins/youtube-embed-plus/images/playhover.png)
Beginner to Advanced Complete Ansible Tutorial in 15 hours 6-2021 Part – 1
![play](https://www.devopsschool.com/blog/wp-content/plugins/youtube-embed-plus/images/playhover.png)
Beginner to Advanced Complete Ansible Tutorial in 15 hours 6-2021 Part – 2
![play](https://www.devopsschool.com/blog/wp-content/plugins/youtube-embed-plus/images/playhover.png)
Beginner to Advanced Complete Ansible Tutorial in 15 hours 6-2021 Part – 3
![play](https://www.devopsschool.com/blog/wp-content/plugins/youtube-embed-plus/images/playhover.png)
Beginner to Advanced Complete Ansible Tutorial in 15 hours 6-2021 Part – 4
![play](https://www.devopsschool.com/blog/wp-content/plugins/youtube-embed-plus/images/playhover.png)
Beginner to Advanced Complete Ansible Tutorial in 15 hours 6-2021 Part – 5
![play](https://www.devopsschool.com/blog/wp-content/plugins/youtube-embed-plus/images/playhover.png)
Beginner to Advanced Complete Ansible Tutorial in 15 hours 6-2021 Part – 6
![play](https://www.devopsschool.com/blog/wp-content/plugins/youtube-embed-plus/images/playhover.png)
Beginner to Advanced Complete Ansible Tutorial in 15 hours 6-2021 Part – 7
![play](https://www.devopsschool.com/blog/wp-content/plugins/youtube-embed-plus/images/playhover.png)
Beginner to Advanced Complete Ansible Tutorial in 15 hours 6-2021 Part – 8
![play](https://www.devopsschool.com/blog/wp-content/plugins/youtube-embed-plus/images/playhover.png)
Beginner to Advanced Complete Ansible Tutorial in 15 hours 6-2021 Part – 9
![play](https://www.devopsschool.com/blog/wp-content/plugins/youtube-embed-plus/images/playhover.png)
Beginner to Advanced Complete Ansible Tutorial in 15 hours 6-2021 Part – 10
![play](https://www.devopsschool.com/blog/wp-content/plugins/youtube-embed-plus/images/playhover.png)
Beginner to Advanced Complete Ansible Tutorial in 15 hours 6-2021 Part – 11
![play](https://www.devopsschool.com/blog/wp-content/plugins/youtube-embed-plus/images/playhover.png)
Beginner to Advanced Complete Ansible Tutorial in 15 hours 6-2021 Part – 12
![play](https://www.devopsschool.com/blog/wp-content/plugins/youtube-embed-plus/images/playhover.png)
Beginner to Advanced Complete Ansible Tutorial in 15 hours 6-2021 Part – 13
![play](https://www.devopsschool.com/blog/wp-content/plugins/youtube-embed-plus/images/playhover.png)
Beginner to Advanced Complete Ansible Tutorial in 15 hours 6-2021 Part – 14
![play](https://www.devopsschool.com/blog/wp-content/plugins/youtube-embed-plus/images/playhover.png)
Beginner to Advanced Complete Ansible Tutorial in 15 hours 6-2021 Part – 15
![loading](https://www.devopsschool.com/blog/wp-content/plugins/youtube-embed-plus/images/gallery-page-loader.gif)
Latest posts by Rajesh Kumar (see all)
- How to remove sensitive warning from ms office powerpoint - July 14, 2024
- AIOps and DevOps: A Powerful Duo for Modern IT Operations - July 14, 2024
- Leveraging DevOps and AI Together: Benefits and Synergies - July 14, 2024