Ansible(2) - Ansible inventory configuration and connectivity testing Ansible配置主机和连接测试教程

1. open the inventory file with your favorite editor and modify it

1
sudo vi /etc/ansible/hosts

add servers likes below:

1
2
3
[servers]
server1 ansible_host=192.168.1.100 ansible_ssh_user=test_user ansible_ssh_pass=password ansible_ssh_extra_args='-o StrictHostKeyChecking=no'
server2 ansible_host=192.168.1.101 ansible_ssh_user=test_user ansible_ssh_pass=password ansible_ssh_extra_args='-o StrictHostKeyChecking=no'

2. verify the inventory

1
ansible-inventory --list -y

image

3. test connectivity by using a Ansible ping

1
ansible all -m ping

image

4. run a testing command from control node to host nodes

1
ansible all -a "df -h"

image

参数说明 args:

  • all: all servers
  • -a: using ad-hoc commands
  • df: disk free
  • -h: –human-readable : print sizes in power of 1024

Ansible(2) - Ansible inventory configuration and connectivity testing Ansible配置主机和连接测试教程

https://yanmouxie.com/ansible-2-inventory-configuration-and-connectivity-testing.html

Author

Yan Mouxie

Posted on

2023-02-12

Updated on

2023-09-20

Licensed under