221216 작업일지

백승한·2022년 12월 16일
0

playbook으로 대상 Host에 폴더/파일 만들기

make_file.yml 1

- name: touch files test
  hosts: all
  tasks:
    - file:
        path: /home/touch_files
        state: directory
           
    - file:
        path: /home/touch_files/test.txt
        state: touch

Error

해결방법

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

make_file.yml 2

- 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

Error

해결방법

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 파일 생성 완료

etc

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
profile
방문해주셔서 감사합니다🙂

0개의 댓글