본문 바로가기

DevOps14

Ansible Roles Ansible에서는 "Role"을 사용하여 일반적인 방식으로 ansible 코드를 더 쉽게 재사용하는 방법을 제공한다. role은 인프라를 프로비저닝하고, 애플리케이션을 배포하는 등의 모든 작업에 대해 변수, 파일, 템플릿 등의 기타 리소스들을 표준화된 디렉토리 구조로 패키징한다. 다시 정리하면, role은 쉬운 공유, 휴대성 및 재사용을 위해 특정 구조로 배열된 yaml 작업파일 및 지원 항목들의 모음이다. playbook에서 role을 가져오기만 하면 미리 지정된 처리해야 할 task를 처리할 수 있다. 그렇다면 playbook 은 role 폴더를 어떻게 찾을까? playbook 안쪽 폴더에서 관리할 수도 있으나 다른 playbook에서 필요 시 중복이 일어날 수 있다. /etc/ansible/ans.. 2023. 6. 28.
Ansible Loops loop 지시문과 변수를 받아 반복을 수행한다. 변수에 방식에 따라 3가지의 방식이 있다. 1.기본 item 변수 사용 - name: test1 hosts: web1.example.com tasks: - name: postfix and httpd are running service: - name: "{{ item }}" state: started loop: - postfix - httpd 2.사용자 정의 변수 사용 - name: test1 hosts: web1.example.com vars: check_services: - postfix - httpd tasks: - name: postfix and httpd are running service: - name: "{{ item }}" state: star.. 2023. 6. 27.
Variable Precedence 변수 우선 순위 우아하게 앤서블 450페이지 https://docs.ansible.com/ansible/2.5/user_guide/playbooks_variables.html Using Variables — Ansible Documentation You should choose where to define a variable based on the kind of control you might want over values. Set variables in inventory that deal with geography or behavior. Since groups are frequently the entity that maps roles onto hosts, you can often set vari docs.ansible.. 2023. 6. 27.
Ansible Variables 앤서블은 플레이북에서 재활용할 수 있도록 변수(variable)를 지원한다. 변수는 다음과 같이 반복적이거나 동적인 값을 관리할 때 편리하다. 여러 사용자를 생성 여러 패키지를 설치 여러 서비스를 재시작 변수 정의하기 플레이북 안에 변수를 정의할 경우 시작 위치에 있는 vars 블록에 변수를 정의한다. 인벤토리에서는 각각의 host 명을 정의하기도 한다 {{ }} 안에 변수명을 입력하여 host ip를 대체할 수 있다. playbook1.yaml - name: 'Update nameserver entry into resolv.conf file on localhost' hosts: localhost tasks: - name: 'Update nameserver entry into resolv.conf fil.. 2023. 6. 27.