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