리눅스

[draft] Ansible ansible-config 명령어를 사용하는 방법

SangChul Dot Kr Blog 2026. 3. 1. 13:31

Ansible ansible-config 명령어를 사용하는 방법

ansible-config란?

ansible-config는 Ansible의 구성(Configuration) 값을 조회·검증·초기화하기 위한 공식 CLI 도구입니다.

ansible-config 도움말 확인

ansible-config -h
$ ansible-config -h
usage: ansible-config [-h] [--version] [-v] {list,dump,view,init} ...

View ansible configuration.

positional arguments:
  {list,dump,view,init}
    list                Print all config options
    dump                Dump configuration
    view                View configuration file
    init                Create initial configuration

optional arguments:
  --version             show program's version number, config file location, configured module search path, module location, executable location and exit
  -h, --help            show this help message and exit
  -v, --verbose         verbose mode (-vvv for more, -vvvv to enable connection debugging)

주요 서브커맨드

  • list : 모든 구성 옵션과 기본값 출력
  • dump : 현재 적용 중인 설정을 실제 값 기준으로 출력
  • view : 사용 중인 ansible.cfg 파일 내용 확인
  • init : 초기 ansible.cfg 템플릿 생성

Ansible 버전 및 설정 파일 위치 확인

ansible-config --version
$ ansible-config --version
ansible-config [core 2.12.8]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/vagrant/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /home/vagrant/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible-config
  python version = 3.8.10 (default, Jun 22 2022, 20:18:18) [GCC 9.4.0]
  jinja version = 2.10.1
  libyaml = True
  • config file : 실제로 적용 중인 ansible.cfg 위치
  • 예상과 다른 설정이 적용될 때 가장 먼저 확인해야 하는 부분

모든 구성 옵션 조회 (list)

ansible-config list
$ 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'
...
YAML_FILENAME_EXTENSIONS:
  default:
  - .yml
  - .yaml
  - .json
  description:
  - Check all of these extensions when looking for 'variable' files which should be
    YAML or JSON or vaulted versions of these.
  - This affects vars_files, include_vars, inventory and vars plugins among others.
  env:
  - name: ANSIBLE_YAML_FILENAME_EXT
  ini:
  - key: yaml_valid_extensions
    section: defaults
  name: Valid YAML extensions
  type: list

list 출력에서 확인 가능한 정보

  • 기본값 (default)
  • 환경 변수 이름 (env)
  • ansible.cfg에서의 위치 (ini)
  • 옵션 타입 (type)
  • 도입된 버전 (version_added)

현재 적용 중인 설정 확인 (dump)

ansible-config dump
  • 실제 실행 시 적용되고 있는 최종 설정값을 출력
  • 기본값 + 사용자 설정이 모두 반영된 결과

변경된 값만 확인

ansible-config dump --only-changed

사용 중인 ansible.cfg 파일 보기 (view)

ansible-config view
$ ansible-config view
# Since Ansible 2.12 (core):
# To generate an example config file (a "disabled" one with all default settings, commented out):
#               $ ansible-config init --disabled > ansible.cfg
#
# Also you can now have a more complete file by including existing plugins:
# ansible-config init --disabled -t all > ansible.cfg

# For previous versions of Ansible you can check for examples in the 'stable' branches of each version
# Note that this file was always incomplete  and lagging changes to configuration settings

# for example, for 2.9: https://github.com/ansible/ansible/blob/stable-2.9/examples/ansible.cfg

초기 ansible.cfg 파일 생성 (init)

기본 예제 (모든 옵션 주석 처리)

ansible-config init --disabled > ansible.cfg

플러그인 포함한 전체 템플릿

ansible-config init --disabled -t all > ansible.cfg

 

참고URL

- https://docs.ansible.com/ansible/latest/reference_appendices/general_precedence.html

- 변군이글루 : Ansible 구성 설정(Configuration Settings) 파일의 우선순위에 대한 설명