How to enable add_host module in Ansible? Let’s look into the details. With our Server Management Services, Bobcares offers solutions to your queries.
How to enable add_host module in Ansible?
The add_host module in Ansible allows users to dynamically add hosts and groups to the Ansible playbook’s in-memory inventory during execution. So,such hosts or groups can be employed as targets in subsequent plays in the same playbook. The extensibility of this module is so great that variables may be used to indicate a host or group name. This simplifies the job when the server is created and setup using the same playbook.
How the module works? This Ansible module works and has the same syntax as another Ansible module written in YAML. As a result, employing it should be simple for an Ansible Administrator. The syntax is shown below:
- name: Adding host to groups add_host: hostname: <hostname or ip of host> groups: - <group1>
The important feature includes:
-
- Variables can be used to generate new hosts and groups in inventory for usage in subsequent plays of the same playbook in this module.
- This module takes variables to allow us to completely specify the new hosts.
- This module is compatible with Windows targets.
- This module skips the play host loop and runs just once for all hosts in the game. If we needs to iterate, use a with-loop construct.
The “add_host” module in Ansible | Examples
- name: Add host to multiple groups add_host: hostname: '{{ new_ip }}' groups: - group1 - group2
– name: Add a host with a non-standard port local to your machines
add_host:
name: ‘{{ new_ip }}:{{ new_port }}’
[Need help with another query? We’re here to help]
Conclusion
In this article, we provide a brief note on the add_host module in Ansible. With the support of our Server management services, we have also given some examples to understand the module better.
PREVENT YOUR SERVER FROM CRASHING!
Never again lose customers to poor server speed! Let us help you.
Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.
var google_conversion_label = "owonCMyG5nEQ0aD71QM";
0 Comments