반응형
1. playbook
[root@ANSIBLE ansible]# cat add_user.yml
---
- name: "user add"
hosts: test01
become: true # 권한 상승
tasks:
- name: "user add" # user 모듈을 사용하여 사용자 추가
user:
name: "{{ add_user_name }}"
password: "{{ upassword | password_hash('sha512') }}"
shell: "/bin/bash"
- name: "Add user to sudoers" # lineinfile 모듈을 사용하여 권한상승 설정 추가
lineinfile:
dest: /etc/sudoers
regexp: "{{ add_user_name }} ALL"
line: "{{ add_user_name }} ALL=(ALL) ALL"
state: present
# - name: Expiring password for user "{{ add_user_name }}" ## 계정의 만료시간 설정
# shell: chage -d 0 "{{ add_user_name }}"
vars: # 변수 정의
add_user_name: test3
upassword: test1212
2. 실행
## 결과
[root@ANSIBLE ansible]# ansible-playbook -i hosts add_user.yml
PLAY [user add] ******************************************************************************************************************************************************************
TASK [Gathering Facts] ***********************************************************************************************************************************************************
ok: [test02]
TASK [user add] ******************************************************************************************************************************************************************
changed: [test02]
TASK [Add user to sudoers] *******************************************************************************************************************************************************
changed: [test02]
PLAY RECAP ***********************************************************************************************************************************************************************
test02 : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
반응형
'Automation Tools > Ansible' 카테고리의 다른 글
1.5 ansible | [test][playbook] 서비스 데몬 실행 (0) | 2021.03.16 |
---|---|
1.4 ansible | [test][playbook] 파일 내용 치환 (0) | 2021.03.16 |
1.3 ansible | [test][playbook] 원격지에서 파일 가져오기 (0) | 2021.03.16 |
1.2 ansible | [test][playbook] 파일 복사와 삭제 (0) | 2021.03.16 |
0. ansible 설치 (0) | 2021.03.16 |