From df432c026bc904a30ba4ef20a1bae667084e4428 Mon Sep 17 00:00:00 2001 From: CuriousLearner Date: Tue, 11 Apr 2017 22:58:47 +0530 Subject: [PATCH 1/3] WIP docker container for running ZNC --- Vagrantfile | 3 ++ playbook.yml | 1 + roles/znc_docker/tasks/main.yml | 66 ++++++++++++++++++++++++++ roles/znc_docker/templates/Dockerfile | 8 ++++ roles/znc_docker/templates/znc.conf.j2 | 37 +++++++++++++++ 5 files changed, 115 insertions(+) create mode 100644 roles/znc_docker/tasks/main.yml create mode 100644 roles/znc_docker/templates/Dockerfile create mode 100644 roles/znc_docker/templates/znc.conf.j2 diff --git a/Vagrantfile b/Vagrantfile index c60ad59..829949c 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -69,5 +69,8 @@ Vagrant.configure(2) do |config| ansible.inventory_path = "hosts" ansible.verbose = "vvv" ansible.limit = "vagrant" + ansible.extra_vars = { + ZNC_ADMIN_PASS_HASH: "sha256#0be7da92c5c868ed70c76629610b6b6791bf17a89ce46bcb7ee91b058da96928#x56AIGENv2nr3_7G:xrn#" + } end end diff --git a/playbook.yml b/playbook.yml index 26814dd..810f35a 100644 --- a/playbook.yml +++ b/playbook.yml @@ -7,3 +7,4 @@ - nginx_redirects - retweet_bot - mumble-server + - znc_docker diff --git a/roles/znc_docker/tasks/main.yml b/roles/znc_docker/tasks/main.yml new file mode 100644 index 0000000..487a87b --- /dev/null +++ b/roles/znc_docker/tasks/main.yml @@ -0,0 +1,66 @@ +--- + +- name: add docker apt key + apt_key: + keyserver: hkp://p80.pool.sks-keyservers.net:80 + id: 58118E89F3A912897C070ADBF76221572C52609D + +- name: add docker apt repository + apt_repository: + repo: deb https://apt.dockerproject.org/repo ubuntu-trusty main + update_cache: yes + +- name: ensure docker and dependencies are installed + apt: name=docker-engine update_cache=yes + +- service: name=docker state=restarted + +- name: create /srv/znc dir and give permission + file: path=/srv/znc owner={{ ansible_ssh_user }} group={{ ansible_ssh_user }} mode=0775 state=directory recurse=yes + sudo: yes + tags: + - configure + +- name: create ~/.znc dir and give permission + file: path=~/.znc/configs owner={{ ansible_ssh_user }} group={{ ansible_ssh_user }} mode=0775 state=directory recurse=yes + sudo: yes + tags: + - configure + +- name: Copy Dockerfile + template: src=Dockerfile dest=/srv/znc/Dockerfile + tags: + - configure + - deploy + +- name: Copy ZNC conf + template: src=znc.conf.j2 dest=/srv/znc/znc.conf + environment: + ZNC_ADMIN_PASS_HASH: "{{ lookup('env', 'ZNC_ADMIN_PASS_HASH') }}" + tags: + - configure + +- name: Copy ZNC conf + template: src=znc.conf.j2 dest=~/.znc/configs/znc.conf + environment: + ZNC_ADMIN_PASS_HASH: "{{ lookup('env', 'ZNC_ADMIN_PASS_HASH') }}" + tags: + - configure + +- name: Install Docker py + pip: + name: docker-py + +- name: build image + docker_image: > + name="curiouslearner/znc" + tag="0.1" + path="/srv/znc" + state=build + +- name: Run ZNC instance + shell: docker run --name pydelhi_znc -d -p 36697:6697 -v ~/.znc:/znc-data curiouslearner/znc:0.1 + sudo: yes + tags: + - configure + - deploy diff --git a/roles/znc_docker/templates/Dockerfile b/roles/znc_docker/templates/Dockerfile new file mode 100644 index 0000000..4282ea6 --- /dev/null +++ b/roles/znc_docker/templates/Dockerfile @@ -0,0 +1,8 @@ +FROM znc:1.6.5 + +MAINTAINER Sanyam Khurana + +RUN mkdir -p znc-data/configs/ +ADD znc.conf znc-data/configs/znc.conf + + diff --git a/roles/znc_docker/templates/znc.conf.j2 b/roles/znc_docker/templates/znc.conf.j2 new file mode 100644 index 0000000..bcee28b --- /dev/null +++ b/roles/znc_docker/templates/znc.conf.j2 @@ -0,0 +1,37 @@ +// WARNING +// +// Do NOT edit this file while ZNC is running! +// Use webadmin or *controlpanel instead. +// +// Altering this file by hand will forfeit all support. +// +// But if you feel risky, you might want to read help on /znc saveconfig and /znc rehash. +// Also check http://en.znc.in/wiki/Configuration + +Version = 1.6.5 + + Port = 3367 + IPv4 = true + IPv6 = false + SSL = false + +LoadModule = webadmin + + + Pass = {{ ZNC_ADMIN_PASS_HASH }} + Admin = true + Nick = curiouslearner + AltNick = curiouslearner_ + Ident = curiouslearner + RealName = Sanyam Khurana + LoadModule = chansaver + LoadModule = controlpanel + + + LoadModule = simple_away + Server = chat.freenode.net +6697 + + + + + From 7e08f558f817a2b3b51cc8b4ae475739c7395c96 Mon Sep 17 00:00:00 2001 From: CuriousLearner Date: Tue, 11 Apr 2017 23:56:00 +0530 Subject: [PATCH 2/3] Fixes tags for Docker ZNC role and support multi-deployment by stoping and removing container --- roles/znc_docker/tasks/main.yml | 40 +++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/roles/znc_docker/tasks/main.yml b/roles/znc_docker/tasks/main.yml index 487a87b..b5d4cbc 100644 --- a/roles/znc_docker/tasks/main.yml +++ b/roles/znc_docker/tasks/main.yml @@ -4,16 +4,30 @@ apt_key: keyserver: hkp://p80.pool.sks-keyservers.net:80 id: 58118E89F3A912897C070ADBF76221572C52609D + tags: + - configure - name: add docker apt repository apt_repository: repo: deb https://apt.dockerproject.org/repo ubuntu-trusty main update_cache: yes + tags: + - configure - name: ensure docker and dependencies are installed apt: name=docker-engine update_cache=yes + tags: + - configure - service: name=docker state=restarted + tags: + - configure + +- name: Install Docker py + pip: + name: docker-py + tags: + - configure - name: create /srv/znc dir and give permission file: path=/srv/znc owner={{ ansible_ssh_user }} group={{ ansible_ssh_user }} mode=0775 state=directory recurse=yes @@ -31,14 +45,6 @@ template: src=Dockerfile dest=/srv/znc/Dockerfile tags: - configure - - deploy - -- name: Copy ZNC conf - template: src=znc.conf.j2 dest=/srv/znc/znc.conf - environment: - ZNC_ADMIN_PASS_HASH: "{{ lookup('env', 'ZNC_ADMIN_PASS_HASH') }}" - tags: - - configure - name: Copy ZNC conf template: src=znc.conf.j2 dest=~/.znc/configs/znc.conf @@ -47,16 +53,26 @@ tags: - configure -- name: Install Docker py - pip: - name: docker-py - - name: build image docker_image: > name="curiouslearner/znc" tag="0.1" path="/srv/znc" state=build + tags: + - configure + +- name: Stop running ZNC instance + shell: docker stop pydelhi_znc + sudo: yes + tags: + - deploy + +- name: Remove stopped ZNC instance + shell: docker rm pydelhi_znc + sudo: yes + tags: + - deploy - name: Run ZNC instance shell: docker run --name pydelhi_znc -d -p 36697:6697 -v ~/.znc:/znc-data curiouslearner/znc:0.1 From 2b2587556c4dbc64ddeb25e1942bec874bc4d71f Mon Sep 17 00:00:00 2001 From: CuriousLearner Date: Wed, 12 Apr 2017 00:01:12 +0530 Subject: [PATCH 3/3] Exposes 36697 port from vagrant to access ZNC webadmin panel --- Vagrantfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Vagrantfile b/Vagrantfile index 829949c..b3a5133 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -23,6 +23,7 @@ Vagrant.configure(2) do |config| # within the machine from a port on the host machine. In the example below, # accessing "localhost:8080" will access port 80 on the guest machine. config.vm.network "forwarded_port", guest: 80, host: 8080 + config.vm.network "forwarded_port", guest: 36697, host: 36697 # Create a private network, which allows host-only access to the machine # using a specific IP.