ansible批量创建用户

使用openssl生成一段加密密码

openssl passwd -1 123

$1$SeDgQgFX$QpKs2kIy7BO7EGk8ipoVM1

配置ansible-playbook

vi public.yml

– hosts: ‘{{ hosts }}’
gather_facts: false
tasks:
– name: useradd aaaa
user: name=aaaa shell=/bin/bash groups=wheel append=yes password=”$1$SeDgQgFX$QpKs2kIy7BO7EGk8ipoVM1″
tags:
– aaaa
– name: mkdir .ssh
file: path=/home/aaaa/.ssh state=directory
tags:
– aaaa
– name: copy key
copy: src=/ansible/user/files/aaaa/authorized_keys dest=/home/aaaa/.ssh/
tags:
– aaaa
– name: change owner
shell: chown -R aaaa.aaaa /home/aaaa/.ssh
tags:
– aaaa
– name: change mod keys
shell: chmod 600 /home/aaaa/.ssh/authorized_keys
tags:
– aaaa
– name: modify sudoers
lineinfile: dest=/etc/sudoer regexp=”^%wheel ALL=(ALL)” line=”%wheel ALL=(ALL) NOPASSWD: ALL”

这里真正的密码并不是$1$SeDgQgFX$QpKs2kIy7BO7EGk8ipoVM1,这是123加密之后的密码,这样既安全又方便

此条目发表在linux分类目录。将固定链接加入收藏夹。

发表评论