- 运维需要管理许多开发人员的pub文件,统一存储在/etc/ansible/user.keypubs/{{ name }}.id_rsa.pub下,
- /etc/ansible/useradd.yml文件,添加zhangsan用户,只需修改vars下的用户、组名和执行的机器组hosts
---
- hosts: centos6
remote_user: dinggel
gather_facts: false
become: yes
vars:
- {name: zhangsan, group: zhangsan}
tasks:
- name: user add
user: name={{ name }}
- name: mkdir /home/{{ name }}/.ssh
file: path=/home/{{ name }}/.ssh state=directory owner={{ name }} mode=0700
- name: user add
action: file path=/home/{{ name }}/.ssh/authorized_keys state=touch owner={{ name }} mode=0600
- name: ssh-copy
authorized_key:
user: "{{ name }}"
key: "{{ lookup('file', '/etc/ansible/user.keypubs/{{ name }}.id_rsa.pub') }}"
path: /home/{{ name }}/.ssh/authorized_keys