sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt-get isntall ansible
測試 ansible --version
2.產生主控端ssh key
sshkey-gen
# 產生 ~/.ssh/id_rsa(private key) id_rsa.pub(public key)
3.複製主控端的id到遠端(被控端)
ssh-copy-id myuser@192.168.0.99
之後使用ssh myuser@192.168.0.9 就不需要輸入密碼
4.設定連線主機資資訊hosts.yml
all:
hosts:
my-99:
ansible_host: 192.168.0.99
ansible_port: 22
ansible_ssh_private_key_file: "~/.ssh./id_rsa"
ansible_user: myuser
ansible_sudo_pass:
5.測試連線
ansible all -i hosts.yml -m ping
或
ansible my-99 -i hosts.yml