Closed beaniejoy closed 1 year ago
서로 다른 OS server에 대한 ansible playbook 범용 관리
[ec2] [ssh_server_ip_addr] ansible_user=ec2-user ansible_ssh_private_key_file=/home/ec2-user/.ssh/[ssh_server_private_key] [rasp_pi] [domain] ansible_port=[port_forwarding] ansible_user=pi ansible_ssh_private_key_file=/home/ec2-user/.ssh/[ssh_server_private_key]
여러 host 등록
# roles/package/vars/main.yml java_package: Amazon: java-17-amazon-corretto Debian: openjdk-17-jre nginx_package: Amazon: nginx Debian: nginx
os별 vars 관리
# roles/package/tasks/main.yml --- - name: Check OS ansible.builtin.debug: msg: "OS: {{ ansible_distribution }} / OS version: {{ ansible_distribution_version }}" tags: - always - name: Install java action: > {{ ansible_pkg_mgr }} name={{ java_package[ansible_distribution] }} state=present tags: - init - name: Install nginx action: > {{ ansible_pkg_mgr }} name={{ nginx_package[ansible_distribution] }} state=present tags: - init
ansible_pkg_mgr: os별로 package manager 적용 ansible_distribution: ansible host에 대한 os version check(gather_facts: true에서 가능)
ansible_pkg_mgr
ansible_distribution
gather_facts: true
Debian nginx 설정 중 주의사항 기록 (링크)
# remote server remote_server_user: Amazon: ec2-user Debian: pi remote_server_group: Amazon: ec2-user Debian: pi remote_user_workspace: "/home/{{ remote_server_user[ansible_distribution] }}" ...
remote server user, group 둘 다 OS별로 관리
서로 다른 OS server에 대한 ansible playbook 범용 관리
hosts
여러 host 등록
install package
os별 vars 관리
ansible_pkg_mgr
: os별로 package manager 적용ansible_distribution
: ansible host에 대한 os version check(gather_facts: true
에서 가능)global vars
remote server user, group 둘 다 OS별로 관리