[ roles init ]
roles directory 생성
$ mkdir roles
$ cd rolse
$ ansible-galaxy init common $ tree common ├── README.md ├── defaults │ └── main.yml ├── files ├── handlers │ └── main.yml ├── meta │ └── main.yml ├── tasks │ └── main.yml ├── templates ├── tests │ ├── inventory │ └── test.yml └── vars └── main.yml
[ roles/common/vars/main.yml ]
미리 변수를 정의하여 tasks에서 사용
name: my-host
[ roles/common/templates/host.my-host.j2 ]
tasks에서 사용할 template정의
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.1.10 main_server 192.168.1.11 storage_server
[ roles/common/tasks/main.yml ]
실제 동작하는 tasks 작성
- name: Install packages yum: name: - wget - unzip become: true - name: modify hosts template: src: ../templates/hosts.{{name}}.j2 dest: /etc/hosts owner: root group: root
[ common.yml ]
최초 실행 playbook
- hosts: '{{ target }}' roles: - common
[ playbook 실행 ]
$ ansible-playbook common.yml --extra-vars "target=my-host" --user=my
댓글 없음:
댓글 쓰기