- hosts: hbase
gather_facts: no
tasks:
- name: enforce env
shell: source /etc/profile
run_once: true
- name: delete /root/.ssh/
file: path=/root/.ssh/ state=absent
- name: generating public/private rsa key pair #生成公钥和私钥
shell: ssh-keygen -t rsa -b 2048 -N '' -f /root/.ssh/id_rsa
- name: view id_rsa.pub #将公钥设置成变量
shell: cat /root/.ssh/id_rsa.pub
register: sshinfo
- set_fact: sshpub={{sshinfo.stdout}}
- name: add ssh record #合并各个节点公钥
local_action: shell echo {{sshpub}} >> /etc/ansible/templates/authorized_keys.j2
- name: copy authorized_keys.j2 to all #分发到各个节点上
template: src=/etc/ansible/templates/authorized_keys.j2 dest=/root/.ssh/authorized_keys mode=0600
tags:
- install ssh_root