공부합시다!/Ansible

Ansible : Nginx Install, Configuration

간서치 2023. 3. 16. 00:14
728x90

Rocky Linux 9인 Ansible을 설치했더니 Ansible 2.13.3버젼으로 올라오네요!

nginx 설치 하고 구성하여 service 실행 및 삭제를 해보았습니다.

Web Contents가 저장되는 Web Root Directory는 /www 변경.

 

1. playbook 작성

---
- name: nginx configuration
  hosts: all 
  tasks:

    - name: nginx install
      yum:
        name: nginx
        state: latest
    
    - name: mkdir /www
      file:
        path: /www
        state: directory

    - name: nginx config
      lineinfile:
        path: /etc/nginx/nginx.conf
        regexp: '^(\s+root\s+)/usr/share/nginx/html;'
        line: "\troot        /www;"

    - name: nginx index.html copy
      copy:
        src: ./index.html
        dest: /www/index.html

    - name: nginx daemon start
      service:
        name: nginx
        state: started

    - name: firewall open
      firewalld:
        port: "{{ item.port }}/{{ item.protocol }}"
        immediate: "{{ item.imme }}"
        permanent: "{{ item.per }}"
        state: "{{ item.sta }}"
      with_items:
      - { port: 80, protocol: tcp, imme: yes, per: yes, sts: enabled }

 

2. Playbook

 

3. 설치 제거

# ansible all -m dnf -a "name=nginx state=absent autoremove=yes"

 

자! 내일은 ansible을 활용하여 이미 학습한 dhcp, vsftpd, web, dns 구성을 자동화 해 보도록 하겠습니다.

Have a nice day!

728x90