Bobcares

For every $500 you spend, we will provide you with a $500 credit on your account*

BLACK FRIDAY SPECIAL EXTENSION

*The maximum is $4000 in credits, Offer valid till December 6th, 2024, New Customers Only, Credit will be applied after purchase and expires after six (6) months

For every $500 you spend, we will provide you with a $500 credit on your account*

BLACK FRIDAY SPECIAL EXTENSION

*The maximum is $4000 in credits, Offer valid till December 6th, 2024, New Customers Only, Credit will be applied after purchase and expires after six (6) months

Add_Host Module In Ansible | Beginners Guide

by | Dec 27, 2022

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.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.