-
ansible rolesansible 2022. 2. 6. 22:39
전체 디렉토리 구조
├── ansible.cfg ├── inventories │ ├── dev │ ├── group_vars │ │ └── all.yml │ └── real ├── playbooks │ └── playbook.yml └── roles └── mysql ├── README.md ├── defaults │ └── main.yml ├── files ├── handlers │ └── main.yml ├── meta │ └── main.yml ├── tasks │ └── main.yml ├── templates ├── tests │ ├── inventory │ └── test.yml └── vars └── main.yml
Role 디렉토리 만들기
위의 roles/mysql 하위 디렉토리 구조가 복잡한데, 아래 명령어로 mysql role 을 작성하는데 디렉토리를 구성할 수 있다.
cd roles ansible-galaxy init mysql
Role 작성하기
roles/mysql/tasks/main.yml 에 tasks 를 작성한다.
- name: Install MySQL Packages yum: name: mysql state: present - name: Configure Database mysql_db: name: db1 state: present
Playbook 에서 role 사용하기
- name: Install and Configure MySQL hosts: db-server roles: - mysql
ansible-galaxy command
ansible-galaxy search mysql ansible-galaxy install geerlingguy.mysql ansible-galaxy list # check role path ansible-config dump | grep ROLE
ansible-galaxy role 사용하기
ansible-galaxy role install
windbird@AL01929730:~$ ansible-galaxy install geerlingguy.mysql - downloading role 'mysql', owned by geerlingguy - downloading role from https://github.com/geerlingguy/ansible-role-mysql/archive/3.3.2.tar.gz - extracting geerlingguy.mysql to /home/windbird/.ansible/roles/geerlingguy.mysql - geerlingguy.mysql (3.3.2) was installed successfully windbird@AL01929730:~$ cd /home/windbird/.ansible/roles/geerlingguy.mysql windbird@AL01929730:~/.ansible/roles/geerlingguy.mysql$ ls LICENSE README.md defaults handlers meta molecule tasks templates vars
playbook 에서 사용
- name: Install and Configure MySQL hosts: db-server roles: - geerlingguy.mysql
'ansible' 카테고리의 다른 글
ansible loops (0) 2022.02.06 ansible conditionals (0) 2022.02.06 ansible variables (0) 2022.02.06 ansible modules (0) 2022.02.06 ansible playbooks (0) 2022.02.06