화요일, 3월 18, 2025
HomeLinuxAnsible Nginx Deployment

Ansible Nginx Deployment

Ansible Nginx Deployment

Ansible를 이용하여 nginx설치 예제 설정방법을 메모합니다.

$ mkdir -p ansible-nignx/tasks
$ touch ansible-nignx/deploy.yml
$ touch ansible-nignx/tasks/install_nginx.yml
$ tree ansible-nignx/
The program 'tree' is currently not installed. You can install it by typing:
sudo apt-get install tree
$ sudo apt-get install tree
sudo: unable to resolve host ansible
[sudo] password for webadm: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  tree
0 upgraded, 1 newly installed, 0 to remove and 3 not upgraded.
Need to get 40.6 kB of archives.
After this operation, 138 kB of additional disk space will be used.
Get:1 http://kr.archive.ubuntu.com/ubuntu/ vivid/universe tree amd64 1.7.0-3 [40.6 kB]
Fetched 40.6 kB in 5s (7,912 B/s)       
Selecting previously unselected package tree.
(Reading database ... 90066 files and directories currently installed.)
Preparing to unpack .../tree_1.7.0-3_amd64.deb ...
Unpacking tree (1.7.0-3) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up tree (1.7.0-3) ...
$ tree ansible-nignx/
ansible-nignx/
├── deploy.yml
└── tasks
    └── install_nginx.yml

1 directory, 2 files
$ nano ansible-nignx/deploy.yml
- hosts: nginx
  remote_user: user
  become: yes
  become_method: sudo

  tasks:
    - include: 'tasks/install_nginx.yml'
$ touch ansible-nignx/hosts
$ nano ansible-nignx/hosts
[nginx]
172.16.16.250
$ nano ansible-nignx/tasks/install_nginx.yml
- name: NGINX | Adding NGINX signing key
  apt_key: url=http://nginx.org/keys/nginx_signing.key state=present
 
- name: NGINX | Adding sources.list deb url for NGINX
  lineinfile: dest=/etc/apt/sources.list line="deb http://nginx.org/packages/mainline/ubuntu/ trusty nginx"
 
- name: NGINX Plus | Adding sources.list deb-src url for NGINX
  lineinfile: dest=/etc/apt/sources.list line="deb-src http://nginx.org/packages/mainline/ubuntu/ trusty nginx"
 
- name: NGINX | Updating apt cache
  apt:
    update_cache: yes
 
- name: NGINX | Installing NGINX
  apt:
    pkg: nginx
    state: latest
 
- name: NGINX | Starting NGINX
  service:
    name: nginx
    state: started
$ cd ansible-nignx
$ ansible-playbook -i hosts deploy.yml

PLAY ***************************************************************************

TASK [setup] *******************************************************************
ok: [172.16.16.250]

TASK [include] *****************************************************************
included: /home/user/ansible-nignx/tasks/install_nginx.yml for 172.16.16.250

TASK [NGINX | Adding NGINX signing key] ****************************************
changed: [172.16.16.250]

TASK [NGINX | Adding sources.list deb url for NGINX] ***************************
changed: [172.16.16.250]

TASK [NGINX Plus | Adding sources.list deb-src url for NGINX] ******************
changed: [172.16.16.250]

TASK [NGINX | Updating apt cache] **********************************************
ok: [172.16.16.250]

TASK [NGINX | Installing NGINX] ************************************************
changed: [172.16.16.250]

TASK [NGINX | Starting NGINX] **************************************************
ok: [172.16.16.250]

PLAY RECAP *********************************************************************
172.16.16.250              : ok=8    changed=4    unreachable=0    failed=0  

ansible_nginx

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular