Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
Ansible is a Red Hat-sponsored open-source community project that offers the simplest method to automate IT. Ansible is the only automation language that can be utilized by entire IT teams, from system administrators to network administrators to developers and managers.
This article will explain what advanced execution is using the Ansible framework.
How to Limit Execution by Tasks in Ansible
This is a critical execution technique in which only one execution is required rather than the complete playbook. For example, assume you just want to halt a server (in case of a production issue) and then restart it after deploying a patch.
Stop and start were part of separate roles in the original playbook; however, this may be addressed with the use of tags. We can assign different tags to different roles (which include tasks), and thus just that specific role/task is executed based on the tags assigned by the executor. So, for the preceding example, we may add tags like the following:
- {role: start-tomcat, tags: ['install']}}
The following command facilitates the use of tags:
The above command will just invoke the start-tomcat role. The provided tag is case-sensitive. Ensure that the command receives an accurate match.
How to Limit Execution by Hosts in Ansible
There are two methods for executing specified tasks on certain hosts. One defines the hosts for a certain role - the precise hosts that specific role should run on.
Example
- hosts: <A>
environment: "{{your env}}"
pre_tasks:
- debug: msg = "Deployment Started!.
Your Current time: {{ansible_date_time.date}} {{ansible_date_time.time}} "
roles:
- {role: <your role>, tags: ['<respective tag>']}
post_tasks:
- debug: msg = "Deployment Completed.
Your Current time: {{ansible_date_time.date}} {{ansible_date_time.time}}"
- hosts: <B>
pre_tasks:
- debug: msg = "Started!
Your Current time: {{ansible_date_time.date}} {{ansible_date_time.time}} "
roles:
- {role: <your role>, tags: ['<respective tag>']}
post_tasks:
- debug: msg = "Task Completed!
Your Current time: {{ansible_date_time.date}} {{ansible_date_time.time}}"
According to the preceding example, the corresponding roles will only be called based on the hosts specified. The host A and B are now defined in the host's table (inventory file).
Alternate Solution
A possible approach could be to define the playbook's hosts as a variable, then send in a specific host address through —extra-vars.
If no {{target}} is specified, the playbook does nothing. If necessary, a group from the host's file can be passed through. If the extra vars are not provided, this has no effect.
Ansible can be used to provision your environment's underlying infrastructure, network devices, virtualized hosts, bare metal servers, and hypervisors. It can also install services, add compute hosts, and provision cloud resources, services, and applications.
Is Ansible based on Python?
Ansible is developed in Python and has a relatively short learning curve. Ansible is a straightforward installation process and does not require any additional software, servers, or client daemons. It maintains nodes over SSH by default and is parallel.
What tool is Ansible?
Ansible is a free and open-source IT automation software that automates configuration management, application deployment, provisioning, orchestration, and a variety of other manual IT tasks.
What is the Ansible playbook?
Ansible Playbooks are a set of tasks that are executed automatically against hosts. Your Ansible inventory is made up of host groups. Each module in an Ansible Playbook is in charge of a specific task. Each module has metadata indicating when and where a task is completed, as well as which user completes it.
Is Ansible a programming language?
Ansible is a configuration management system built in Python that employs a declarative markup language to describe configurations.
Conclusion
In this article, we have discussed the following topics Limiting execution of tasks, Limiting Execution by hosts and Playbook Targeting a single host