- 安装
pip install ansible
- 手动创建ansible.cfg
sudo mkdir /etc/ansible/ansible.cfg
- 查看ansible配置信息
ansible --version
- 创建hosts文件
cd /etc/ansible/
sudo touch hosts
sudo vi hosts
添加主机IP
127.0.0.1
- ansible 是基于 ssh协议实现的,所以其配置公私钥的方式与 ssh 协议的方式相同,具体操作步骤如下:
生成私钥
ssh-keygen
向主机分发私钥
ssh-copy-id [email protected]
- 测试Ping
ansible -u root 127.0.0.1 -m ping
成功
127.0.0.1 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
失败
127.0.0.1 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: ssh: connect to host 127.0.0.1 port 22: Connection refused",
"unreachable": true
}
标签:MacOS,127.0,0.1,sudo,ansible,HelloWorld,Ansible,hosts,ssh
From: https://www.cnblogs.com/luoxiaolei/p/17806680.html