name
hosts
gather_facts
tasks
remote_user
ansible.builtin.command
vars_files
Ansible Playbook(플레이북) 설명 및 예시
Host 매개변수 설정 가이드
How to Include Variables in Ansible + Examples
Ansible 자주 사용하는 모듈
$ cat conditional test
---
- name: test
hosts: all
tasks:
- name: create directory
file:
path: /home/ansible/rhel7
state: directory
- name: touch file
file:
path: /home/ansible/rhel7/test.txt
state: touch
when:
- ansible_distribution == "RedHat"
- ansible_distribution_major_version == "7"
...
when 옵션을 활용하여 해당 조건을 만족하는 경우에 task 수행
경로 : /etc/ansible/ansible.cfg
Remote_user : 사용자 이름
Remote_port : SSH 연결 디폴트 포트
기업에서 사용하는 경우, Root의 직접 접근이 불가능하여, sudo를 이용하여 root 접근방식과 동일하게 시행할 수 있다. 이를 위해서는 "/etc/sudoers 파일에 자신의 계정을 등록" 해주면 된다.
Sudo 사용시 암호를 쓰도록 할 경우,
"ask_sudo_pass" 값을 true로 설정
Role : 이미 정의된 Ansible content(Task, Handler, Variable, Plugin, 등)를 재사용하기 위해서 사용한다. 역할을 정의하고 directory별로 분리한다.