From cf9556f643d6d5d3d627777a2d96ac78f959e8b6 Mon Sep 17 00:00:00 2001 From: Martin van Es <martin@mrvanes.com> Date: Wed, 30 Mar 2022 15:44:44 +0200 Subject: [PATCH] WIP --- inventory/local | 1 + playbook.yml | 2 ++ roles/geodns/defaults/main.yml | 4 ---- roles/geodns/tasks/main.yml | 13 ------------- .../geodns/templates/geodns-update.service.j2 | 2 +- roles/geodns/templates/geodns-update.timer.j2 | 2 +- roles/local/defaults/main.yml | 5 +++++ roles/local/tasks/main.yml | 18 ++++++++++++++++++ roles/mdproxy/tasks/main.yml | 8 ++++++-- .../templates/mdproxy-update.service.j2 | 12 ++++++++++++ .../mdproxy/templates/mdproxy-update.timer.j2 | 9 +++++++++ 11 files changed, 55 insertions(+), 21 deletions(-) create mode 100644 roles/local/defaults/main.yml create mode 100644 roles/local/tasks/main.yml create mode 100644 roles/mdproxy/templates/mdproxy-update.service.j2 create mode 100644 roles/mdproxy/templates/mdproxy-update.timer.j2 diff --git a/inventory/local b/inventory/local index ff50ec0..d33c048 100644 --- a/inventory/local +++ b/inventory/local @@ -6,6 +6,7 @@ local ansible_connection=local # Hosts that receive the mdproxy role [mdproxy] +local # Hosts that receive the GeoDNS role [geodns] diff --git a/playbook.yml b/playbook.yml index f890492..fa49cdb 100644 --- a/playbook.yml +++ b/playbook.yml @@ -8,6 +8,7 @@ hosts: geodns gather_facts: false roles: + - {role: local, tags: ['local']} - {role: geodns, tags: ['geodns']} - name: MDSigner @@ -21,5 +22,6 @@ hosts: mdproxy gather_facts: false roles: + - {role: local, tags: ['local']} - {role: apache, tags: ['apache']} - {role: mdproxy, tags: ['mdproxy']} diff --git a/roles/geodns/defaults/main.yml b/roles/geodns/defaults/main.yml index 291d8ef..18ad3dd 100644 --- a/roles/geodns/defaults/main.yml +++ b/roles/geodns/defaults/main.yml @@ -8,7 +8,3 @@ geodns_version: v3.2.0 geodns_config: "{{ geodns_dir}}/config" geolite_dir: "{{ geodns_dir }}/GeoLite2DB" - -mdxsaas_repo: https://gitlab.geant.org/TI_Incubator/mdx-saas-config.git -mdxsaas_dir: /opt/mdx-saas -mdxsaas_version: main diff --git a/roles/geodns/tasks/main.yml b/roles/geodns/tasks/main.yml index 83b8b9f..6e09285 100644 --- a/roles/geodns/tasks/main.yml +++ b/roles/geodns/tasks/main.yml @@ -3,7 +3,6 @@ apt: state: present name: - - ansible - netcat-openbsd - name: Install Ansible community.general @@ -101,15 +100,3 @@ - geodns-update.timer notify: - "enable geodns job" - -- name: Clone MDX-SAAS-config repository - ansible.builtin.git: - repo: "{{ mdxsaas_repo }}" - dest: "{{ mdxsaas_dir }}" - version: "{{ mdxsaas_version }}" - register: mdxsaas_git - -- name: Write MDX-SAAS repo version - ansible.builtin.shell: - cmd: "git rev-parse HEAD > {{ geodns_config }}/revision" - chdir: "{{ mdxsaas_dir }}" diff --git a/roles/geodns/templates/geodns-update.service.j2 b/roles/geodns/templates/geodns-update.service.j2 index 17b702c..b548274 100644 --- a/roles/geodns/templates/geodns-update.service.j2 +++ b/roles/geodns/templates/geodns-update.service.j2 @@ -5,7 +5,7 @@ Description=GeoDNS update Type=oneshot WorkingDirectory={{ mdxsaas_dir }} ExecStart=git pull -ExecStart=ansible-playbook playbook.yml -i inventory/local --tags geodns --limit local +ExecStart=ansible-playbook playbook.yml -i inventory/local --tags local,geodns --limit local ExecStartPost=/bin/systemctl restart geodns [Install] diff --git a/roles/geodns/templates/geodns-update.timer.j2 b/roles/geodns/templates/geodns-update.timer.j2 index 0a4e475..0241bae 100644 --- a/roles/geodns/templates/geodns-update.timer.j2 +++ b/roles/geodns/templates/geodns-update.timer.j2 @@ -2,7 +2,7 @@ Description=Run GeoDNS update [Timer] -OnCalendar=*-*-* *:0/5:00 +OnCalendar=*-*-* *:02:00 Unit=geodns-update.service [Install] diff --git a/roles/local/defaults/main.yml b/roles/local/defaults/main.yml new file mode 100644 index 0000000..8b71038 --- /dev/null +++ b/roles/local/defaults/main.yml @@ -0,0 +1,5 @@ +--- + +mdxsaas_repo: https://gitlab.geant.org/TI_Incubator/mdx-saas-config.git +mdxsaas_dir: /opt/mdx-saas +mdxsaas_version: main diff --git a/roles/local/tasks/main.yml b/roles/local/tasks/main.yml new file mode 100644 index 0000000..5791679 --- /dev/null +++ b/roles/local/tasks/main.yml @@ -0,0 +1,18 @@ +--- +- name: Install packages + apt: + state: present + name: + - ansible + +- name: Clone MDX-SAAS-config repository + ansible.builtin.git: + repo: "{{ mdxsaas_repo }}" + dest: "{{ mdxsaas_dir }}" + version: "{{ mdxsaas_version }}" + register: mdxsaas_git + +- name: Write MDX-SAAS repo version + ansible.builtin.shell: + cmd: "git rev-parse HEAD > {{ geodns_config }}/revision" + chdir: "{{ mdxsaas_dir }}" diff --git a/roles/mdproxy/tasks/main.yml b/roles/mdproxy/tasks/main.yml index 92fd204..fa1e33c 100644 --- a/roles/mdproxy/tasks/main.yml +++ b/roles/mdproxy/tasks/main.yml @@ -13,7 +13,11 @@ - name: Copy mdproxy service files ansible.builtin.template: - src: "mdproxy.service.j2" - dest: "/etc/systemd/system/mdproxy.service" + src: "{{ item }}.j2" + dest: "/etc/systemd/system/{{ item }}" + with_items: + - mdproxy.service + - mdproxy-update.service + - mdproxy-update.timer notify: - "enable mdproxy job" diff --git a/roles/mdproxy/templates/mdproxy-update.service.j2 b/roles/mdproxy/templates/mdproxy-update.service.j2 new file mode 100644 index 0000000..bcdce65 --- /dev/null +++ b/roles/mdproxy/templates/mdproxy-update.service.j2 @@ -0,0 +1,12 @@ +[Unit] +Description=mdproxy update + +[Service] +Type=oneshot +WorkingDirectory={{ mdxsaas_dir }} +ExecStart=git pull +ExecStart=ansible-playbook playbook.yml -i inventory/local --tags local,mdproxy --limit local +ExecStartPost=/bin/systemctl restart mdproxy + +[Install] +WantedBy=multi-user.target diff --git a/roles/mdproxy/templates/mdproxy-update.timer.j2 b/roles/mdproxy/templates/mdproxy-update.timer.j2 new file mode 100644 index 0000000..9806d2c --- /dev/null +++ b/roles/mdproxy/templates/mdproxy-update.timer.j2 @@ -0,0 +1,9 @@ +[Unit] +Description=Run mdproxy update + +[Timer] +OnCalendar=*-*-* *:04:00 +Unit=mdproxy-update.service + +[Install] +WantedBy=timers.target -- GitLab