본문 바로가기

분류 전체보기26

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.
Ansible Conditionals 플레이 북에서 팩트 (원격 시스템에 대한 데이터), 변수 또는 이전 작업의 결과 값에 따라 다른 작업을 실행하거나 다른 목표를 가질 수 있다. 일부 변수의 값이 다른 변수의 값에 종속되도록 할 수 있다. 또는 호스트가 다른 기준과 일치하는지 여부에 따라 추가 호스트 그룹을 생성 할 수 있다. 조건부로이 모든 것을 할 수 있다. # Inventory # We have created a group for web servers. Similarly create a group for database servers named 'db_servers' and add db1 server to it # -------------------------------- # Sample Inventory File # Web Serv.. 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.