You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- hosts: tnode1-centos.exp.com
vars:
fedora_os:
- CentOS
- RedHat
net_info:
- con_name: enp7s0
ip_addr: 192.168.20.5/24
ip_gw: 192.168.20.1
ip_dns: 192.168.20.1
tasks:
- name: Include role in CentOS and RedHat
ansible.builtin.include_role:
name: myrole.nmcli
when: ansible_facts.distribution in fedora_os
- name: Include role in Ubuntu
ansible.builtin.include_role:
name: myrole.netplan
when: ansible_facts.distribution == "Ubuntu"
ansible-playbook 디렉토리 구조
main.yml : 프로젝트의 최상단
/roles : 프로젝트 내 수행할 작업에 대한 sub 디렉토리
ㄴ /role_name1 : 하위 role의 이름
ㄴ /tasks : role 안에서 수행할 task들이 위치한 디렉토리
ㄴ main.yml : tasks 디렉토리 밑의 파일은 기본적으로 main.yml을 우선 참조한다.
ㄴ sub_task1.yml
ㄴ ...
ㄴ /vars : role에서 참조할 변수들을 작성하는 디렉토리
ㄴ /files : role에서 참조할 기타 파일들이 위치한 디렉토리
ㄴ /handler : task 수행 후 별도로 실행해야 하는 사항을 작성하는 디렉토리. task에서 notify로 호출
/vars : 프로젝트 전체에서 사용하는 변수. ansible-playbook에서 실행하는 경우 extra_vars로, AWX에서 실행하는 경우 variable 항목에서 지정 가능
하위 태스크를 호출하는 방법
include 모듈을 사용하여 호출: main playbook에서 하위 role 호출 시 include_roles을 사용
또는 role의 main.yml에서 하위 task를 호출할 때 include_tasks를 사용
김수빈님의 Nix 사용기 (앤서블 대체)
https://medium.com/@sudosubin/%EC%8A%AC%EA%B8%B0%EB%A1%AD%EA%B2%8C-dotfiles-%EA%B4%80%EB%A6%AC%ED%95%98%EA%B8%B0-e66b3a280c6f
https://www.youtube.com/watch?v=Y5NHZ1YXnM4