컬쥐네 다락방

Ansible | 구성 파일 및 권한 설정 본문

클라우드/Ansible

Ansible | 구성 파일 및 권한 설정

코딩하는 갱얼쥐 2022. 4. 14. 02:21

구성 파일

설정파일 위치

  1. ANSIBLE_CONFIG (environment variable if set)
touch /tmp/ans.cfg 
export ANSIBLE_CONFIG=/tmp/ans.cfg 
ansible --version

unset ANSIBLE\_CONFIG  
ansible --version
  1. ansible.cfg (현재 작업 디렉토리)
  2. ~/.ansible.cfg (홈디렉토리)
  3. /etc/ansible/ansible.cfg : 기본 설정 파일

관리 노드 접속

SSH 접속 방법

  • 패스워드 인증
  • 키 쌍 인증

권한 상승(Privilege Escalation)

  • su(X)
  • sudo

/etc/sudoers

%wheel ALL=(ALL) ALL
  • %wheel: wheel 그룹
  • ALL : 모든 시스템에서
  • (ALL) : 모든 사용자로
  • ALL : 모든 명령어

/etc/sudoers.d/vagrant

%vagrant ALL=(ALL) NOPASSWD: ALL
  • NOPASSWD: 패스워드 묻지 않음(passwordless sudo)

ansible* 옵션

SSH 접속 옵션

  • -u REMOTE_USER, --user REMOTE_USER : SSH 접속 계정(기본: 현재 사용자)
  • -k, --ask-pass : 옵션 사용 SSH 패스워드 인증
    • 옵션 사용하지 않으면 --> SSH 키 인증

ansible의 기본 인증 방법: SSH 키 인증

권한 상승 옵션

  • -b, --become : 권한 상승
    • 옵션 사용하지 않으면 --> 권한상승 하지 않음
  • --become-method <sudo|su>
    • sudo: 기본값
    • su
  • --become-user : 어떤 사용자?
    • root: 기본값
  • -K, --ask-become-pass : sudo 패스워드 묻기
    • 옵션 사용하지 않으면 --> Passwordless sudo

설정 파일

[defaults]  
remote_user=  
ask_pass=<True|False>  
host_key_checking=<True|False>

[privilege_escalation]  
become=<True|False>  
become_ask_pass=<True|False>  
become_method=<sudo|su>  
become_user=
  • ask_pass 기본값: false
  • host_key_checking 기본값: true
  • become 기본값: false
  • become_ask_pass 기본값: false
  • become_method 기본값: sudo

ansible-config 명령

  • ansible-config list : 설정 가능한 모든 항목 표시
  • ansible-config dump : 모든 설정의 기본 값 및 변경 값 표시
  • ansible-config view : 현재 적용되는 설정 파일의 내용 표시

ansible -cofig 명령

  • ansible-config list : 설정 가능한 모든 항목 표시
[vagrant@controller ~]$ ansible-config list  
ACTION_WARNINGS:  
default: true  
description: \[By default Ansible will issue a warning when received from a task  
action (module or action plugin), These warnings can be silenced by adjusting  
this setting to False.]  
env:

-   {name: ANSIBLE_ACTION_WARNINGS}  
    ini:
-   {key: action_warnings, section: defaults}  
    name: Toggle action warnings  
    type: boolean  
    version_added: '2.5'  
    AGNOSTIC_BECOME_PROMPT:  
    default: true  
    description: Display an agnostic become prompt instead of displaying a prompt containing  
    the command line supplied become method  
    env:
-   {name: ANSIBLE_AGNOSTIC_BECOME_PROMPT}  
    ini:
-   {key: agnostic_become_prompt, section: privilege_escalation}  
    name: Display an agnostic become prompt  
    type: boolean  
    version_added: '2.5'  
    yaml: {key: privilege_escalation.agnostic_become_prompt}  
    ALLOW_WORLD_READABLE_TMPFILES:  
    default: false  
    description: \[This makes the temporary files created on the machine to be world  
    readable and will issue a warning instead of failing the task., It is useful  
    when becoming an unprivileged user.]  
    :
  • ansible-config dump
    • 초록색 : 이상없이 실행했지만 변경이 없음
    • 노란색 : 실행했고 변경이 있음
    • 빨간색 : 무언가 문제가 있음

'클라우드 > Ansible' 카테고리의 다른 글

Ansible | Playbook  (0) 2022.04.18
Ansible | Ad_hoc  (0) 2022.04.18
Ansible | 인벤토리  (0) 2022.04.14
Ansible | SSH  (0) 2022.04.12
Ansible | 기초 개념  (0) 2022.04.12
Comments