配置个人ansible工作目录,编写自动免密yml文件

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

你可能感兴趣的:(Linux学习日记)