- name: touch files test
hosts: all
tasks:
- file:
path: /home/touch_files
state: directory
- file:
path: /home/touch_files/test.txt
state: touch
become: true 추가
- name: touch files test
hosts: all
become: true
tasks:
- file:
path: /home/touch_files
state: directory
- file:
path: /home/touch_files/test.txt
state: touch
Ansible troubleshooting — Permission denied Errno 13
- name: touch files test
hosts: all
become: true
tasks:
- file:
path: /home/touch_files
state: directory
- file:
path: /home/touch_files/test.txt
state: touch
become -> become_user: root 추가
- name: touch files test
hosts: all
become_user: root
tasks:
- file:
path: /home/han/touch_files
state: directory
- file:
path: /home/han/touch_files/test.txt
state: touch
이전 설정했던 become
은 특정 사용자로 전환(become)할지 여부이고, true/false/yes/no로 설정한다.
그리고 어떤 사용자로 전환될지는 become_user
로 설정하면 된다.
아래 처럼 필요한 task에서만 become
으로 설정을 on/off 할 수 있다.
become_user
역시 become
과 마찬가지로 세부 task에서만 설정할 수도 있다.
[Ansible] sudo 대신 become 사용하기
Ansible troubleshooting - missing sudo password and incorrect sudo password
touch_files 폴더 / test.txt 파일 생성 완료
ansible Missing sudo password
ansible "msg": "Missing sudo password"
- name: touch files test
hosts: all
become_user: root
tasks:
- file:
path: /home/han/touch_files
state: directory
- file:
path: /home/han/touch_files/test.txt
state: touch