ansible
这是本文档旧的修订版!
ansible
Usage
Add public key to server
0. Install sshpass
first:
sudo pacman -S sshpass
1. Edit host inventory, add server host like this:
- host
[test] test1 ansible_ssh_host=1.1.1.1 test2 ansible_ssh_host=2.2.2.2
2. Create upload_ssh_keys.yml
:
- upload_ssh_keys.yml
--- - hosts: all remote_user: root tasks: - name: upload key to server authorized_key: user: root state: present key: "{{ lookup('file', lookup('env', 'HOME') + '/.ssh/id_rsa.pub') }}"
3. Run ansible-playbook
command and input password:
ansible-playbook -k -l test upload_ssh_keys.yml
Handling SSH host key prompts
When you first time connected to server, it would prompts you something like this:
The authenticity of host 'xxx (x.x.x.x)' can't be established. ED25519 key fingerprint is xxxxxxxx. Are you sure you want to continue connecting (yes/no)?
Solution: disable SSH key host checking:
- ansible.cfg
[defaults] host_key_checking = False
ansible.1501766676.txt.gz · 最后更改: (外部编辑)