보조기억장치
ansible yaml example 본문
2 TASK
install_apache.yml
- hosts: all
become: true
tasks:
- name: install apache2 and php package(CENTOS)
dnf:
name:
- httpd
- php
state: latest
update_cache: yes
when: ansible_distribution == "CentOS"
- name: install apache2 and php package(UBUNTU)
apt:
name:
- apache2
- libapache2-mod-php
state: latest
update_cache: yes
when: ansible_distribution == "Ubuntu"
1 TASK (패키지 모듈 사용)
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/package_module.html
ansible.builtin.package module – Generic OS package manager — Ansible Documentation
Note This module is part of ansible-core and included in all Ansible installations. In most cases, you can use the short module name package even without specifying the collections: keyword. However, we recommend you use the FQCN for easy linking to the mo
docs.ansible.com
inventory
192.168.0.112 apache_package=httpd php_package=php
192.168.0.113 apache_package=httpd php_package=php
192.168.0.40 apache_package=apache2 php_package=libapache2-mod-php
install_apache.yml
---
- hosts: all
become: true
tasks:
- name: install apache2 and php package
package:
name:
- "{{ apache_package }}"
- "{{ php_package }}"
state: latest
update_cache: yes
group
inventory
[web_server]
192.168.0.112
[db_server]
192.168.0.113
[file_server]
192.168.0.40
ansible-group.yml
---
- hosts: all
become: true
pre_tasks:
- name: install updates (CentOS)
dnf:
update_only: yes
update_cache: yes
when: ansible_distribution == "CentOS"
- name: install updates (Ubuntu)
apt:
upgrade: dist
update_cache: yes
when: ansible_distribution == "Ubuntu"
- hosts: web_server
become: true
tasks:
- name: install apache2 and php package(UBUNTU)
apt:
name:
- apache2
- libapache2-mod-php
state: latest
when: ansible_distribution == "Ubuntu"
- name: install apache2 and php package(CENTOS)
dnf:
name:
- httpd
- php
state: latest
when: ansible_distribution == "CentOS"
- hosts: db_server
become: true
tasks:
- name: install mariadb package (CentOS)
dnf:
name: mariadb
state: latest
when: ansible_distribution == "CentOS"
- name: install mariadb package (Ubuntu)
apt:
name: mariadb
state: latest
when: ansible_distribution == "Ubuntu"
- hosts: file_server
become: true
tasks:
- name: install samba package
package:
name: samba
state: latest
'Linux' 카테고리의 다른 글
우분투(Ubuntu) IP변경 하기 (0) | 2025.02.03 |
---|---|
우분투 시간대(timezone) 변경하기 (0) | 2025.02.03 |
ubuntu apt update 에러 (0) | 2023.05.09 |
ansible 테스트 (0) | 2023.05.08 |
ansible 설정 (0) | 2023.05.08 |