Saki's 研究记录

Mac 环境部署 Ansible

字数统计: 231阅读时长: 1 min
2022/07/07

安装

mac上使用 brew安装 ansible:

1
brew install ansible

安装完成后进行验证:

1
ansible --version

基础功能

建立一个文件夹,例如在 Documents下建立一个名为 ansible的目录:

1
mkdir -p ~/Documents/ansible

接着在目录下建立一个 hosts文件,命令:

1
vim ~/Documents/ansible/hosts

內容如下:

1
2
3
4
5
6
7
[localhost]
127.0.0.1 ansible_ssh_user=root ansible_ssh_port=22

[all:vars]
ansible_connection=ssh
ansible_user=username
ansible_ssh_pass=pass_word

以上都准备好之后就可以使用 ansibleping module了!
命令与结果如下:

1
2
3
4
5
6
7
8
ansible all -m ping -i ~/Documents/ansible/hosts
127.0.0.1 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/local/bin/python3.6"
},
"changed": false,
"ping": "pong"
}

以上操作和网上找到的大多数教程有点差异,不一样的地方有:

  • 没有在 /etc/ansible下建 hosts
  • 执行 ansible指令时多了一个参数 -i(inventory)

原因是因为在 mac环境下,要存取 /etc下的文件有點麻烦。

以上。

CATALOG
  1. 1. 安装
  2. 2. 基础功能