官术网_书友最值得收藏!

Configuring hosts in the inventory

As we have seen, the entire Ansible configuration is in the ansible.cfg file. However, this configuration is generic and applies to all Ansible executions as well as connectivity to hosts.

However, when using Ansible to configure VMs from different environments or roles with different permissions, it is important to have different connectivity configurations, such as different admin users and SSL keys per environment. For this reason, it is possible to override the default Ansible configuration in the inventory file by configuring specific parameters per host defined in this inventory.

The main configuration parameters that can be overridden are as follows:

  • ansible_user: This is the user who connects to the remote host.
  • ansible_port: It is possible to change the default value of the SSH port.
  • ansible_host: This is an alias for the host.
  • ansible_connection: This is the type of connection to the remote host and can be Paramiko, SSH, or local.
  • ansible_private_key_file: This is the private key used to connect to the remote host.
The complete list of parameters is available in the following documentation:  https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#list-of-behavioral-inventory-parameters.

Here is an example of an inventory in which we configure the connection of hosts:

[webserver]
webserver1 ansible_host=192.10.20.31 ansible_port=2222
webserver2 ansible_host=192.10.20.31 ansible_port=2222

[database]
database1 ansible_host=192.20.34.20 ansible_user=databaseuser
database2 ansible_host=192.20.34.21 ansible_user=databaseuser

[dev]
webserver1
database1

[qa]
webserver2
database2

The following can be seen in this inventory example:

  • The connection information has been specified beside each host.
  • The alias implementation (such as webserver1 and webserver2) is used in another group (such as the qa group in this example).

Having completed the implementation of an Ansible inventory, we will now look at how to test this inventory.

主站蜘蛛池模板: 新沂市| 淮安市| 河北省| 镇沅| 大石桥市| 如东县| 涞水县| 漳州市| 肃宁县| 刚察县| 和政县| 綦江县| 安庆市| 连云港市| 鄂托克前旗| 长沙市| 会昌县| 景宁| 日喀则市| 贵州省| 都昌县| 刚察县| 平陆县| 靖西县| 淮北市| 乐东| 张家港市| 汽车| 宁德市| 峨眉山市| 鄂州市| 铅山县| 民和| 江门市| 舒兰市| 全椒县| 余江县| 浏阳市| 龙山县| 宾阳县| 阿瓦提县|