跳到主要内容

Mac 上使用 Ansible

安装

Ansible 是一个Python编写的自动化运维工具,可以通过Python的包管理工具pip进行安装,也可以通过MacOS的包管理工具Homebrew进行安装

# 使用 pip 安装
pip install ansible
# 使用 Homebrew 安装
brew install ansible

配置

Ansible 的配置文件通常位于 /etc/ansible/ansible.cfg,在MacOS上也可以在用户主目录下创建一个 .ansible.cfg 文件来进行配置

/etc/ansible/ansible.cfg
[defaults]
remote_port = 22
gathering = smart
host_key_checking = False # 禁用主机密钥检查
display_skipped_hosts = False # 不显示跳过的主机
retry_files_enabled = False # 禁用重试文件
[privilege_escalation]
[paramiko_connection]
[ssh_connection]
ssh_args = -o ControlMaster=auto -o ControlPersist=3600s # 复用 SSH 连接
control_path = /tmp/ansible-ssh-%%h-%%p-%%r # 控制路径
pipelining = True # 启用管道化
sftp_batch_mode = True # 启用 SFTP 批处理模式
[accelerate]
[selinux]