1. 程式人生 > >Ubuntu下Ansible安裝和使用

Ubuntu下Ansible安裝和使用

lan 安裝和使用 light pos blank hosts HR test posit

Ansible是一個批量部署的工具

參考:Ansible中文權威指南

1.安裝

sudo apt-get install software-properties-common
sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt-get install ansible

2.在/etc/ansible/hosts文件中添加服務器的ip

vim /etc/ansible/hosts

3.需要將自己機器的~/.ssh/目錄下公鑰,即pub文件,添加到服務器的~/.ssh/authorized_keys文件中

vim ~/.ssh/authorized_keys

測試ssh是否可以免密登錄

4.測試能否ping通,以root用戶登錄

ansible all -m ping -u root

5.測試建立一個test文件夾

ansible all -u root -a "/bin/mkdir test"

Ubuntu下Ansible安裝和使用