ansbile-----------------------02. 批理管理基础模块( 主机清单)
1. 列出ansible 帮助信息
ansible-doc -l
/command(模块名)
2. 列出ansible具体模块的详细说明
ansible-doc -s fetch #(fetch具体模块帮助信息)

ansible-doc fetch #(fetch具体模块帮助信息)剧本使用(Playbook)

03. 如何配置主机清单
第一种方式: 分组配置主机信息
[web]
172.16.1.7
172.16.1.8
172.16.1.9
[data]
172.16.1.31
172.16.1.41
操作过程
[root@m01 ansible-playbook]# ansible data -a "hostname"
172.16.1.31 | CHANGED | rc=0 >>
nfs01
172.16.1.41 | CHANGED | rc=0 >>
backup
[root@m01 ansible-playbook]# ansible web -a "hostname"
172.16.1.7 | CHANGED | rc=0 >>
web01
第二种方式: 主机名符号匹配配置
[web]
172.16.1.[7:9]
[web]
web[01:03]
第三种方式: 跟上非标准远程端口
[web]
web01:52113
172.16.1.7:52113
第四种方式: 主机使用特殊的变量
[web]
172.16.1.7 ansible_ssh_port=52113 ansible_ssh_user=root ansible_ssh_pass=123456
[web]
web01 ansible_ssh_host=172.16.1.7 ansible_ssh_port=52113 ansible_ssh_user=root ansible_ssh_pass=123456
第五种方式: 主机组名嵌入配置
[rsync:children] --- 嵌入子组信息
rsync_server
rsync_client
[rsync_server]
172.16.1.41
[rsync_client]
172.16.1.31
172.16.1.7
[web:vars] --- 嵌入式变量信息
ansible_ssh_host=172.16.1.7
ansible_ssh_port=52113
ansible_ssh_user=root
ansible_ssh_pass=123456
[web]
web01
主机清单的配置方法:
https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html
浙公网安备 33010602011771号