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

最新文章

  1. 可分组的选择框控件(MVVM下)(Toggle样式 仿造单选框RadioButton,复选框CheckBox功能)
  2. bzoj 1503 splay
  3. 3、JS中的语句
  4. [Tomcat 源码分析系列] (附件) : catalina.bat 脚本
  5. Eclipse环境下配置spket中ExtJS提示
  6. LeetCode——TwoSum
  7. 利用win10自带的系统配置禁止开机启动项和程序
  8. TCP/IP的那些事--子网掩码
  9. 第1次作业:no blog no fun
  10. 01基于配置文件方式的SpringMVC,三种HandlerMapping,三种控制器
  11. 最长上升子序列(LIS)
  12. WPF 如何创建自己的WPF自定义控件库
  13. topcoder srm 684 div1
  14. sql server 查看列备注、类型、字段大小
  15. tf.truncated_normal的用法
  16. POI按行读取word,并去掉属性标签内容:超链接
  17. 0x01 译文:Windows桌面应用Win32开发简介
  18. Mysql导出导入数据库
  19. Python开发MapReduce系列(一)WordCount Demo
  20. [AHOI2009]中国象棋 BZOJ1801 dp

热门文章

  1. eclipse打包
  2. 18.C++-[ ]操作符使用 、函数对象与普通函数区别(详解)
  3. Object.defineProperty实现数据绑定
  4. Spark Kudu 结合
  5. 造轮子-Java泛型堆排
  6. 设计模式 --> (6)原型模式
  7. kvm之十二:虚拟机迁移
  8. react的基本使用,及常用填坑
  9. Beta冲刺 第四天
  10. 团队作业6——展示博客(Alpha版本)