Ansible - Special 변수 - 1 > Ansible 자료실

본문 바로가기
사이트 내 전체검색

Ansible 자료실

운영 Ansible - Special 변수 - 1

페이지 정보

profile_image
작성자 snow
댓글 0건 조회 488회 작성일 24-08-07 13:13

본문

Ansible Special 변수

이 게시글에서는 Ansible Special 변수에 대한 문서를 살펴보고, 예시만 안내드리는 글입니다.


1. Magic 변수

Magic 변수는 사용자가 직접 설정할 수 없으며, Ansible이 내부 상태를 반영하기 위해 항상 덮어쓰는 변수들입니다.


1.1. ansible_check_mode

ansible_check_mode는 현재 체크 모드인지 여부를 나타내는 부울 값입니다.

```bash

ansible-playbook playbook.yml --check

```

 

해당 명령을 실행할 시 실제 변경 없이 변경 사항을 시뮬레이션합니다.


1.2. ansible_diff_mode

ansible_diff_mode는 현재 차이 모드인지 여부를 나타내는 부울 값입니다.

```bash

ansible-playbook playbook.yml --diff

```

 

해당 명령을 실행할 시 파일의 변경 전후 차이를 보여줍니다.


1.3. ansible_forks

ansible_forks는 실행 가능한 최대 병렬 프로세스 수를 나타내는 정수 값입니다.

```bash

ansible-playbook -i inventory playbook.yml -f 10

```

 

해당 명령을 실행할 시 최대 10개의 병렬 작업이 실행됩니다.


1.4. ansible_inventory_sources

ansible_inventory_sources는 인벤토리로 사용되는 소스 목록입니다.

```bash

ansible-inventory --list

```

 

해당 명령을 실행할 시 현재 사용 중인 인벤토리 소스 목록을 출력합니다.


2. Role 변수

Role 변수는 현재 실행 중인 역할과 관련된 변수들입니다.


2.1. ansible_parent_role_names

ansible_parent_role_names는 현재 역할을 포함하는 역할의 목록입니다.

```yaml

- name: Print parent role names

  debug:

    msg: "{{ ansible_parent_role_names }}"

```

 

해당 명령을 실행할 시 현재 역할의 부모 역할 이름 목록을 출력합니다.


2.2. ansible_parent_role_paths

ansible_parent_role_paths는 부모 역할의 경로 목록입니다.

```yaml

- name: Print parent role paths

  debug:

    msg: "{{ ansible_parent_role_paths }}"

```

 

해당 명령을 실행할 시 현재 역할의 부모 역할 경로 목록을 출력합니다.


3. Inventory 변수

Inventory 변수는 인벤토리와 관련된 변수들입니다.


3.1. inventory_hostname

inventory_hostname는 현재 호스트의 인벤토리 이름입니다.

```yaml

- name: Print inventory hostname

  debug:

    msg: "{{ inventory_hostname }}"

```

 

해당 명령을 실행할 시 현재 호스트의 인벤토리 이름을 출력합니다.


3.2. inventory_hostname_short

inventory_hostname_short는 현재 호스트 이름의 짧은 버전입니다.

```yaml

- name: Print short inventory hostname

  debug:

    msg: "{{ inventory_hostname_short }}"

```

 

해당 명령을 실행할 시 현재 호스트 이름의 짧은 버전을 출력합니다.


4. Execution 변수

Execution 변수는 Ansible 실행과 관련된 변수들입니다.


4.1. ansible_play_name

ansible_play_name은 현재 실행 중인 플레이의 이름입니다.

```yaml

- name: Print play name

  debug:

    msg: "{{ ansible_play_name }}"

```

 

해당 명령을 실행할 시 현재 실행 중인 플레이의 이름을 출력합니다.


4.2. playbook_dir

playbook_dir은 실행 중인 플레이북의 디렉터리 경로입니다.

```yaml

- name: Print playbook directory

  debug:

    msg: "{{ playbook_dir }}"

```

 

해당 명령을 실행할 시 현재 실행 중인 플레이북의 디렉터리 경로를 출력합니다.

이와 같은 Ansible의 Special 변수들은 다양한 상황에서 유용하게 사용될 수 있습니다. 시니어 OS 엔지니어 학습자 여러분들이 이를 통해 Ansible을 더욱 효과적으로 활용할 수 있기를 바랍니다.

댓글목록

등록된 댓글이 없습니다.

회원로그인

회원가입

사이트 정보

회사명 : (주)리눅스데이타시스템
대표이사 : 정정모
본사 : 강남구 봉은사로 114길 40 홍선빌딩 2층
- tel : 02-6207-1160
대전지사 : 유성구 노은로174 도원프라자 5층
- tel : 042-331-1161

접속자집계

오늘
728
어제
1,372
최대
3,935
전체
1,011,741
Copyright © www.linuxdata.org All rights reserved.