ansible批量加用户

ansible批量加用户

1、生成密码
pip install passlib
python -c "from passlib.hash import sha512_crypt; print sha512_crypt.encrypt('123456')"

2、文件一 hosts.yaml
all:
  vars:
    ansible_connection: ssh
    ansible_user: zhangs
    ansible_ssh_pass: zhangs@123456
    ansible_sudo_pass: zhangs@123456
    ansible_sudo: true
    ansible_sudo_user: root
    become: yes
  children:
    newhosts:
      vars:
        user_name: lis
        user_passwd: "$6$rounds=656000$iK2VjWcO/smQYSZ3$rTr6sbEDRUlWM47Ak72oYqNl8LYrMhXEjFJI..f5gVpTIiRiWvcyd5kWxuDvdDe6LASVXU3cYJkd1NjZrxnBW1"
      hosts:
        192.168.0.0:



3、文件二 playbook.yaml

- name: add admin user
  hosts: newhosts
  become: yes
  become_method: sudo
  vars:
    current_date: "{{ansible_date_time.date}}"
    sudoer_path: /etc/sudoers.d
    user_sudo_file: "{{sudoer_path}}/{{user_name}}"
  tasks:
    - name: add user
      user:
        name: "{{user_name}}"
        password: "{{user_passwd}}"
        home: "/home/{{user_name}}"
    - name: create sudo file
      shell: "touch {{user_sudo_file}}"
    - name: add sudoers
      shell: "echo '{{user_name}}  ALL=(ALL)  NOPASSWD:ALL' > {{user_sudo_file}}"
    - name: chmod sudo file
      shell: "chmod 400 {{user_sudo_file}}"

      
4、执行
ansible-playbook ./playbook.yaml -i hosts.yaml

 

转载于:https://www.cnblogs.com/themost/p/8761007.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值