Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- snmp test
- subporcess path
- python os
- 1697
- InfluxDB
- c3 초
- telegraf
- 백준
- selinux port 등록
- linux시간으로 변경
- 정규식 활용
- c3 second
- CentOS7
- python subprocess
- c3 step graph
- semanage
- gcc 업데이트
- snmp
- gcc regex
- 정규식 컴파일
- g++ 업데이트
- c3 축 가리기
- influxdb 설치
- centos pyhon 설치
- c3 축 없애기
- 정규식 문자열 출력
- c++ 정규식
- grafana dashboard
- python popen
- regex_search
Archives
- Today
- Total
리셋 되지 말자
[Ansible] ubuntu에서 ansible playbook을 이용한 nginx 설치 및 삭제 본문
Vagrantfile
Vagrant.configure("2") do |config|
#ansible-client001
config.vm.define "ansible-client001" do |cfg|
cfg.vm.box = "ubuntu/bionic64"
cfg.vm.provider "virtualbox" do |vb|
vb.name = "ansible-client001"
vb.cpus = 2
vb.memory = 2048
end
cfg.vm.host_name = "ansible-client001"
cfg.vm.network "private_network", ip: "192.168.56.101", :adapter => 2
end
#ansible-server
config.vm.define "ansible-server" do |cfg|
cfg.vm.box = "ubuntu/bionic64"
cfg.vm.provider "virtualbox" do |vb|
vb.name = "ansible-server"
vb.cpus = 2
vb.memory = 2048
end
cfg.vm.host_name = "ansible-server"
cfg.vm.network "private_network", ip: "192.168.56.100", :adapter => 2
cfg.vm.provision "shell", inline: "apt install -y software-properties-common && apt-add-repository ppa:ansible/ansible && apt update -y && apt install -y ansible"
end
end
ssh 설정은 생략 ping 모듈 동작 확인
- ping 테스트
vagrant@ansible-server:~$ ansible clients -m ping
192.168.56.101 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"ping": "pong"
}
playbook
- install_webserver.yml
vagrant@ansible-server:~$ cat install_webserver.yml
---
- name: install nginx on the client
hosts: clients
become: yes
tasks:
- name: update apt repo and cache
apt: update_cache=yes force_apt_get=yes
- name: install nginx
action: apt name=nginx state=present
- name: start nginx
service: name=nginx state=started
- remove_webserver.yml
vagrant@ansible-server:~$ cat remove_webserver.yml
---
- name: remove nginx on the client
hosts: clients
become: yes
tasks:
- name: stop nginx
service:
name: nginx
state: stopped
- name: remove nginx
apt:
name: nginx
state: absent
playbook 실행
- install and start
vagrant@ansible-server:~$ ansible-playbook install_webserver.yml
PLAY [install nginx on the client] **********************************************************************************************************
TASK [Gathering Facts] **********************************************************************************************************************
ok: [192.168.56.101]
TASK [update apt repo and cache] ************************************************************************************************************
changed: [192.168.56.101]
TASK [install nginx] ************************************************************************************************************************
changed: [192.168.56.101]
TASK [start nginx] **************************************************************************************************************************
ok: [192.168.56.101]
PLAY RECAP **********************************************************************************************************************************
192.168.56.101 : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- nginx 설치 확인
vagrant@ansible-client001:~$ dpkg -l | grep -i nginx
ii libnginx-mod-http-geoip 1.14.0-0ubuntu1.9 amd64 GeoIP HTTP module for Nginx
ii libnginx-mod-http-image-filter 1.14.0-0ubuntu1.9 amd64 HTTP image filter module for Nginx
ii libnginx-mod-http-xslt-filter 1.14.0-0ubuntu1.9 amd64 XSLT Transformation module for Nginx
ii libnginx-mod-mail 1.14.0-0ubuntu1.9 amd64 Mail module for Nginx
ii libnginx-mod-stream 1.14.0-0ubuntu1.9 amd64 Stream module for Nginx
ii nginx 1.14.0-0ubuntu1.9 all small, powerful, scalable web/proxy server
ii nginx-common 1.14.0-0ubuntu1.9 all small, powerful, scalable web/proxy server - common files
ii nginx-core 1.14.0-0ubuntu1.9 amd64 nginx web/proxy server (standard version)
- nginx 동작 확인
- stop and remove
vagrant@ansible-server:~$ ansible-playbook remove_webserver.yml
PLAY [remove nginx on the client] ***********************************************************************************************************
TASK [Gathering Facts] **********************************************************************************************************************
ok: [192.168.56.101]
TASK [stop nginx] ***************************************************************************************************************************
changed: [192.168.56.101]
TASK [remove nginx] ************************************************************************************************************************
changed: [192.168.56.101]
PLAY RECAP **********************************************************************************************************************************
192.168.56.101 : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- nginx 미동작 확인
- nginx 삭제가 안됨 1
vagrant@ansible-client001:~$ dpkg -l | grep nginx
ii libnginx-mod-http-geoip 1.14.0-0ubuntu1.9 amd64 GeoIP HTTP module for Nginx
ii libnginx-mod-http-image-filter 1.14.0-0ubuntu1.9 amd64 HTTP image filter module for Nginx
ii libnginx-mod-http-xslt-filter 1.14.0-0ubuntu1.9 amd64 XSLT Transformation module for Nginx
ii libnginx-mod-mail 1.14.0-0ubuntu1.9 amd64 Mail module for Nginx
ii libnginx-mod-stream 1.14.0-0ubuntu1.9 amd64 Stream module for Nginx
ii nginx-common 1.14.0-0ubuntu1.9 all small, powerful, scalable web/proxy server - common files
ii nginx-core 1.14.0-0ubuntu1.9 amd64 nginx web/proxy server (standard version)
- nginx 삭제가 안됨 2
vagrant@ansible-client001:~$ systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Fri 2021-06-11 07:20:26 UTC; 2min 0s ago
Docs: man:nginx(8)
Process: 19508 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=2)
Process: 18762 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 18751 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 18763 (code=exited, status=0/SUCCESS)
- remove_webserver.yml 파일 수정 (autoremove 옵션 추가)
vagrant@ansible-server:~$ cat remove_webserver.yml
---
- name: remove nginx on the client
hosts: clients
become: yes
tasks:
- name: stop nginx
service:
name: nginx
state: stopped
- name: remove nginx
apt: name=nginx state=absent autoremove=yes
참고 : https://sysnet4admin.blogspot.com/2017/06/ansible-playbook-nginx-3.html#.YMMELpozYaw
- nginx 삭제 결과
vagrant@ansible-client001:~$ dpkg -l | grep -i nginx
rc libnginx-mod-http-geoip 1.14.0-0ubuntu1.9 amd64 GeoIP HTTP module for Nginx
rc libnginx-mod-http-image-filter 1.14.0-0ubuntu1.9 amd64 HTTP image filter module for Nginx
rc libnginx-mod-http-xslt-filter 1.14.0-0ubuntu1.9 amd64 XSLT Transformation module for Nginx
rc libnginx-mod-mail 1.14.0-0ubuntu1.9 amd64 Mail module for Nginx
rc libnginx-mod-stream 1.14.0-0ubuntu1.9 amd64 Stream module for Nginx
rc nginx-common 1.14.0-0ubuntu1.9 all small, powerful, scalable web/proxy server - common files
nginx-common은 ubuntu에 직접 들어가서 지워도 삭제가 안된다고 한다
purge 옵션으로 삭제
sudo apt remove --purge nginx*
이렇게 삭제하면 다 삭제되기는 한다.
최종 remove_webserver.yml 수정
vagrant@ansible-server:~$ cat remove_webserver.yml
---
- name: remove nginx on the client
hosts: clients
become: yes
tasks:
- name: stop nginx
service:
name: nginx
state: stopped
- name: remove nginx
apt: name=nginx state=absent autoremove=yes purge=yes
참고 : https://askubuntu.com/questions/457040/cannot-remove-nginx
- 삭제됐는지 확인
vagrant@ansible-client001:~$ dpkg -l | grep -i nginx
vagrant@ansible-client001:~$
삭제 되었다...
후기
편하긴 하지만, 어떤 도구던 잘 사용하기 위해서 공부가 필요하다...
'Infra' 카테고리의 다른 글
[Ansible] ansible wait for connection module (0) | 2021.06.12 |
---|---|
[Ansible] ansible set timezone (0) | 2021.06.11 |
[Ansible] ssh key 관련 정리 - ansible 명령어에 private key 지정 (0) | 2021.06.11 |
[Terraform] AWS - Lightsail 생성 (0) | 2021.06.09 |
[Terraform] AWS - 보안그룹 out boud 규칙 - egress all 설정 (0) | 2021.06.07 |
Comments