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

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.

主站蜘蛛池模板: 安塞县| 鹤庆县| 光泽县| 洱源县| 文登市| 武义县| 高阳县| 周至县| 汝城县| 凤台县| 会宁县| 延安市| 涪陵区| 鄂伦春自治旗| 绥宁县| 建宁县| 杭锦旗| 涟源市| 清徐县| 宁阳县| 西吉县| 东城区| 从化市| 黄大仙区| 新昌县| 广元市| 广平县| 荆州市| 古蔺县| 六盘水市| 安新县| 武乡县| 额济纳旗| 本溪市| 吴江市| 青铜峡市| 莫力| 清苑县| 房产| 四子王旗| 永济市|