mkdir /root/2019ansible
cd /root/2019ansible
vim ansible.cfg
[defaults]
inventory = hosts
remote_user = root
vim hosts
[webservers]
node1.sina.com
node2.sina.com
vim auth_key.yml
---
- name: configure authorized key
hosts: all
tasks:
- name: auth key
authorized_key:
user: root
state: present
key: "{{ lookup('file', '/root/.ssh/id_rsa.pub') }}"
执行命令
ansible-playbook auth_key.yml -k