首页 > 系统服务 > 详细

linux 批量创建用户

时间:2019-10-26 22:11:05      阅读:117      评论:0      收藏:0      [点我收藏+]

user 模块添加用户

python -c 'from passlib.hash import sha512_crypt; import  getpass;  print (sha512_crypt.encrypt(getpass.getpass()))'    #python3 生成密码

ansible all -m user -a "name=admin password=$Mf6OK/7vjBDxZbjo$6Nj10h0Oa1fEoULbObgVcVWMT1XwCBR home=/app/admin createhome=yes"        #使用user模块创建用户

批量修改用户密码

##### playbook###
---
- hosts: k8s
  gather_facts: false
  tasks:
  - name: change user passwd
    user: name={{ item.name }} password={{ item.chpass | password_hash('sha512') }}  update_password=always
    with_items:
      - { name: 'admin', chpass: '123456' }
      - { name: 'test', chpass: '123456' }
      - { name: 'nginx', chpass: '123456' }

####然后执行
ansible-playbook -i /etc/xxxx all playbook

添加sudo 权限

ansible -i xxxxxxx all -m shell -a '
echo "
admin ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers'

playbook 添加具有sudo 权限的用户

---
- hosts: all
  vars:
    user: admin
    password: "$6$rounds=100000$O2BHfT2XIF6oDb9w$8Hhv4vOrLN6JF/nRVYDd8zZdnn9TNkQutyYYywIcPF2kRiHgkwAjqHIN7sDUkd1DcjLRABWT9ULHZPBOF2bZS/"
  remote_user: root
  tasks:
  - name: Add user {{ user }}
    user: name={{user}} comment="ceph user" password={{ password }}
  - name: Config /etc/sudoers
    lineinfile: dest=/etc/sudoers state=present  line='{{item}}' validate='visudo -cf %s'
    with_items:
           - "{{ user}} ALL=(ALL) NOPASSWD: ALL"
           - "Defaults: {{user}}  !requiretty"

linux 批量创建用户

原文:https://www.cnblogs.com/fan-gx/p/11745699.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!