目录
ansible文档:
https://docs.ansible.com/ansible/latest/index.html
一、入门
1.安装pipx
sudo apt update
sudo apt install pipx
pipx ensurepath
sudo pipx ensurepath --global # optional to allow pipx actions with --global argument
2.安装特定版本ansible
pipx install ansible-core==2.17.5
安装完提示
执行pipx ensurepath
3.生成示例ansible.cfg文件
您可以生成一个完全注释掉的示例ansible.cfg
文件,例如:
$ ansible-config init --disabled > ansible.cfg
您还可以拥有一个包含现有插件的更完整的文件:
$ ansible-config init --disabled -t all > ansible.cfg
4.优先类别
Ansible 提供了四个控制其行为的来源。按优先级从最低(最容易覆盖)到最高(覆盖所有其他)的顺序,类别如下:
配置设置
命令行选项
剧本关键字
变量
直接赋值
每个类别都会覆盖所有优先级较低的类别的任何信息。例如,剧本关键字将覆盖任何配置设置。
在每个优先类别中,都有特定的规则适用。但是,一般来说,“最后定义的”优先,并覆盖任何先前的定义。
二、ansible主机配置
1. /etc/ansible/hosts手动创建
控制节点访问其他被控制节点的方式是通过设置SSH免密登录实现的
查看已有的清单配置
ansible-inventory --list
测试被控制节点链接
ansible xxx.xxx.7.xxx -m ping -i ./hosts
roles、inventory 指定路径
在/etc/ansible/ansible.cfg文件中变更配置