Dùng SSH Pass với Ansible để connect vào server

Spread the love

Mở đầu

Chẳng là mình thường dùng ansible với ssh key thay vì dùng user name và password. Chẳng may trong cty lại dùng user name và password. Refer bên dưới thì bị lỗi

inventory

# file: development

[webservers_dev]

xx.xx.xx.xx ansible_ssh_host=xx.xx.xx.xx ansible_private_key_file= ansible_ssh_user=nstaff ansible_ssh_pass=password

Chạy thử thì bị lỗi

~/project/ ansible -m ping webservers_dev
133.242.21.8 | FAILED! => {
    "msg": "to use the 'ssh' connection type with passwords, you must install the sshpass program"
}

Cài đặt thử sshpass thì :

~/project/
Error: No available formula with the name "sshpass"
We won't add sshpass because it makes it too easy for novice SSH users to
ruin SSH's security.

Giải quyết

Ok tốt thôi không cho mình cài đặt sshpass

Chạy thử câu lệnh

 brew install http://git.io/sshpass.rb 
######################################################################## 100.0%
==> Downloading http://sourceforge.net/projects/sshpass/files/sshpass/1.05/sshpass-1.05.tar.gz
==> Downloading from https://sourceforge.net/projects/sshpass/files/sshpass/1.05/sshpass-1.05.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/sshpass/1.05
==> make install
🍺  /usr/local/Cellar/sshpass/1.05: 9 files, 40.7KB, built in 28 seconds
 khanh@kainguennoMacBook-puro  ~/project/16:49:01
sshpass: stable 1.05
http://sourceforge.net/projects/sshpass
/usr/local/Cellar/sshpass/1.05 (9 files, 40.7KB) *
  Built from source on 2018-08-28 at 16:48:58
From: /usr/local/opt/sshpass/.brew/sshpass.rb

Chạy thử lại một lần nữa

ansible -m ping webservers_dev                                                                                                           
xx.xx.xx.xx | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

Ngon vậy là sau này không cần ssh vào server để pull source nữa vì đã có ansible rồi.
Mình sẽ share một bài về ansible sau : D

<

p>

Leave a Reply

Your email address will not be published. Required fields are marked *