Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Info
title목차

Table of Contents

Ansible 설정 우선 순위

Info
titleAnsible.cfg 설정 우선순위
  1. Global
    1. /etc/ansible/ansible.cfg
  2. 사용자권한에 귀속
    1. ~/.ansible/ansible.cfg
  3. Custom Diractory
    1. /demo/ansible.cfg
  4. 환경 변수
    1. ansible ${option parameters}

Ansible 작업 디렉토리 구조

  • Ansible --version 명령어로 config file 경로를 확인 할 수 있습니다.
Code Block
title작업디렉터리 구조 및 Config File위치
[devops@work-vm devops-lab]$ pwd
/home/devops/devops-lab
[devops@work-vm devops-lab]$ tree
.
├── ansible.cfg
└── inventory
    └── inventory

1 directory, 2 files

Ansible 설정파일 - ansible.cfg

Info
titleConfig File

[devops@work-vm devops-lab]$ cat ansible.cfg

Code Block
titleansible.cfg
linenumberstrue
[defaults]
inventory = inventory
remote_user = devops
ask_pass = false

[privilege_escalation]
become=false
become_method=sudo
become_user=root
become_ask_pass=false


Ansible 설정 파일 - inventory

Info
titleinventory

[devops@work-vm devops-lab]$ cat inventory/inventory

Code Block
titleinventory/inventory
linenumberstrue
[web]
web01-vm
web02-vm
web03-vm


Ansible 설정 정보 학인

Info
titleConfig File설정 정보 확인

[devops@work-vm

devops-lab]$

ansible

--version

Code Block
titleconfig file
linenumberstrue
ansible 2.9.1
  config file = /home/devops/devops-lab/ansible.cfg
  configured module search path = [u'/home/devops/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Jul 13 2018, 13:06:57) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]




ansible.cfg
Info
titleinventory 설정 확인

[devops@work-vm

devops-lab]$

ansible web --list-hosts

Code Block
title
inventory설정 확인
linenumberstrue
  hosts (3):
    web01-vm
    web02-vm
    web03-vm



Ansible 설정 테스트

Info
titleping 호출해보기

[devops@work-vm

devops-lab]$

cat ansible.cfg [defaults] inventory = inventory remote_user = devops ask_pass = false [privilege_escalation] become=false become_method=sudo become_user=root become_ask_pass=false
Code Block
titleinventory/inventory
linenumberstrue

ansible web -m ping

Code Block
titleping 호출 처리결과
linenumberstrue
web01-vm | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}
web03-vm | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}
web02-vm | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}
[devops@work-vm devops-lab]$ cat inventory/inventory [web] web01-vm web02-vm web03-vm