Inventory:
inventory是命名主机的集合,文件为/etc/ansible/hosts
范例1:(可解析的主机名或者IP)
blue.example.com |
[webservers] alpha.example.org beta.example.org 192.168.1.100 192.168.1.110 |
www[001:006].example.com |
[mysql:children] #多级组 组名mysql
mysql_master
mysql_slave
mysql_proxy
[mysql_master]
192.168.80.100
[mysql_slave]
192.168.80.101
[mysql_proxy]
192.168.80.200
|
范例5:定义变量
172.26.1.169 ansible_ssh_user=text 设置远程主机,远程管理主机账号
常见还有:
ansible_ssh_port=22 远程主机端口
ansible_ssh_host 指定被管理主机
ansible_ssh_private_key_file 指定KEY文件
host_key_checking=False 当第一次远程连接主机时,跳过yes和no
|
ansible命令的用法:
Usage: ansible <host-pattern> [options]
范例:ansible all -m command -a 'ifconfig'
说明:all 表示inventory定义的主机或者群集,可以是IP,all代表所有主机
-m:指定模块,不指定默认是command
-a:模块参数
其中常见模块的介绍下一篇blog专门介绍
ansible-doc的常见用法:
-l:查询ansible的所有模块
-s 模块名:查询模块的具体用法
范例:ansible-doc -s user 查询user模块的用法
ansible-playbook:定义播放档(个人理解),让自动化执行
评论区