-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathinit-users.yml
36 lines (35 loc) · 1.03 KB
/
init-users.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
---
- hosts: localvm
become: true
# 引用变量文件
vars_files:
- vars/default.yml
tasks:
# Sudo 用户组配置
- name: Make sure we have a 'wheel' group
group:
name: wheel
state: present
# 允许 'wheel' 组里的用户执行sudo可以不输入用户密码
- name: Make sudo command without password
lineinfile:
path: /etc/sudoers
state: present
regexp: '^%wheel'
line: '%wheel ALL=(ALL) NOPASSWD: ALL'
validate: '/usr/sbin/visudo -cf %s'
# 创建远程命令执行的用户,并配置ssh密钥
- name: Create a new regular user with sudo privileges
user:
name: "{{ create_user }}"
state: present
groups: wheel
append: true
create_home: true
shell: /bin/bash
# 将本地 ssh 公钥注入远程授权访问秘钥文件
- name: Set authorized key for remote user
authorized_key:
user: "{{ create_user }}"
state: present
key: "{{ copy_local_key }}"