Ansible when conditional explained - Part 9

Ansible when conditional explained - Part 9

5.180 Lượt nghe
Ansible when conditional explained - Part 9
▬▬▬▬▬▬ 🎉 🔥 Udemy Course - AWS Networking Zero to Hero!🔥 🎉▬▬▬▬▬▬ 🚀 AWS Networking Masterclass! - https://www.udemy.com/course/aws-networking-zero-to-hero-masterclass/?referralCode=9A38DC3CAF2B02863FF5 ▬▬▬▬▬▬ 🎉 🔥 Udemy Course - Master Azure Like a Pro!🔥 🎉▬▬▬▬▬▬ 🚀 Master Azure Like a Pro! - https://www.udemy.com/course/azure-cloud-zero-to-hero/?referralCode=241EFDDC7859120A5175 ▬▬▬▬▬▬ 🙍🏻‍♂️Join YouTube Membership ▬▬▬▬▬▬ Join this channel to get access to perks: https://www.youtube.com/channel/UC7p4oXcPbgk_yTSHK7QlkSg/join ▬▬▬▬▬▬ 🙍🏻‍♂️ Members Only Videos ▬▬▬▬▬▬ Member Only videos - https://www.youtube.com/playlist?list=UUMO7p4oXcPbgk_yTSHK7QlkSg ▬▬▬▬▬▬ 🗓️ Book Me for Consultation ▬▬▬▬▬▬ Calender - https://tidycal.com/rahulwagh17 ▬▬▬▬▬▬ 🚀 Courses ▬▬▬▬▬▬ 1. Terraform - https://youtu.be/OHzZ7KuioMA 2. Ansible - https://www.youtube.com/watch?v=2hVSpENzhwA&list=PL7iMyoQPMtAPZl58ovoOlxFxNPioSx838 3. Prometheus & Grafana - https://www.youtube.com/watch?v=peH95b16hNI&list=PL7iMyoQPMtAPbN3A7Prac8vfikIPa02wd 4. Helm Chart - https://youtu.be/DQk8HOVlumI 5. Hashi Corp vault - https://www.youtube.com/watch?v=-sU0O82fdZs&list=PL7iMyoQPMtAP7XeXabzWnNKGkCex1C_3C ▬▬▬▬▬▬ ⭐️ Guide and Repository ⭐️ ▬▬▬▬▬▬ Github Repository : https://github.com/rahulwagh/ansible-examples.git The usage of conditionals, which are used to regulate the playbook's flow based on the values of variables or facts, is one of Ansible's key features. We'll talk about Ansible conditionals and how to utilize them in playbooks in this blog article. Similar to conditional statements in programming languages, Ansible uses conditionals. They enable us to declare one set of activities to be carried out in the event of a true condition, and a another set of actions in the event of a false condition. Conditions can be used in tasks, blocks, and loops in Ansible. The "when" phrase is one of the most utilized conditionals in Ansible. We can provide a prerequisite that must be satisfied before a task is executed using the "when" expression. The "when" statement can be used, for instance, to determine whether a package is installed on a remote server before executing a process that depends on it. Here's an illustration: --- - name: Install Apache web server apt: name: apache2 state: present when: ansible_distribution == 'Ubuntu' n this example, the task to install the Apache web server will only be executed if the remote server is running Ubuntu. Conditionals can also be used in loops in Ansible. For example, we can use the "when" statement to filter the items in a loop based on a condition. Here's an example: --- - name: Install multiple packages apt: name: "{{ item }}" state: present when: item in packages_to_install loop: "{{ all_packages }}" In this example, the task will only be executed for packages that are in the "packages_to_install" list. ▬▬▬▬▬▬ ⭐️ Time Stamps ⭐️ ▬▬▬▬▬▬ 0:00 Intro 0:07 What is Ansible Conditional? 0:55 How to implement Ansible Conditional? 02:15 Multiple Conditional 03:44 Conditional on variable 05:41 Conditional with Loop 06:58 Ansible facts with Conditional 08:43 Demo ▬▬▬▬▬▬ ⭐️ Follow me ⭐️ ▬▬▬▬▬▬ Linkedin - https://www.linkedin.com/in/rahul-wagh/ Twitter - https://twitter.com/wagh_rahul To learn more on DevOps visit - https://jhooq.com/ Learn more onto Anisble - https://www.ansible.com/ Disclaimer/Policy: All the content/instructions are solely mine. The source is completely open-source. Video is copyrighted and can not be re-distributed on any platform.