diff options
author | Ole Mathias Heggem <olemathias.aa.heggem@gmail.com> | 2023-11-23 20:14:24 +0100 |
---|---|---|
committer | Ole Mathias Heggem <olemathias.aa.heggem@gmail.com> | 2023-11-23 20:14:24 +0100 |
commit | abd3fba2abb66738c9eac00d3ed86e965584e4a8 (patch) | |
tree | e72f1a30dfec9295f0e09812d73b50c2f2a3973d | |
parent | 09710c061d5b8ae86b3dfe49f4b8936c13a10535 (diff) |
fix: cleanup and format ansible playbook
-rw-r--r-- | ansible/roles/basics/tasks/main.yml | 66 | ||||
-rw-r--r-- | ansible/roles/common/tasks/main.yml | 25 | ||||
-rw-r--r-- | ansible/roles/influx/tasks/main.yml | 31 | ||||
-rw-r--r-- | ansible/roles/ping/handlers/main.yml | 6 | ||||
-rw-r--r-- | ansible/roles/ping/tasks/main.yml | 7 | ||||
-rw-r--r-- | ansible/roles/snmp/tasks/main.yml | 18 | ||||
-rw-r--r-- | ansible/roles/test/tasks/main.yml | 39 | ||||
-rw-r--r-- | ansible/roles/test/vars/main.yml | 18 | ||||
-rw-r--r-- | ansible/roles/web/handlers/main.yml | 25 | ||||
-rw-r--r-- | ansible/roles/web/tasks/main.yml | 129 | ||||
-rw-r--r-- | ansible/site.yml | 25 |
11 files changed, 144 insertions, 245 deletions
diff --git a/ansible/roles/basics/tasks/main.yml b/ansible/roles/basics/tasks/main.yml deleted file mode 100644 index 6a92a19..0000000 --- a/ansible/roles/basics/tasks/main.yml +++ /dev/null @@ -1,66 +0,0 @@ -- command: pwd - register: pwd - tags: - - build - - stop - - start - - test -- name: make all - docker_image: - state: present - docker_api_version: 1.18 - name: "{{ item.name }}" - dockerfile: build/test/{{ item.name }}.Dockerfile - path: "{{ pwd.stdout }}" - force: true - rm: false - with_items: "{{ images }}" - tags: - - build - -- name: stop all - docker: - name: "{{ item.name }}" - docker_api_version: 1.18 - state: stopped - image: "{{ item.name }}" - stop_timeout: 2 - with_items: "{{ images }}" - tags: - - stop - -- name: start all - docker_container: - name: "{{ item.name }}" - image: "{{ item.name }}" - docker_api_version: 1.18 - state: started - network_mode: bridge - recreate: true - restart: true - published_ports: "{{ item.ports }}" - links: "{{ item.links }}" - volumes: "{{ item.volumes }}" - with_items: "{{ images }}" - tags: - - start -- name: workaround to get gondul-varnish-front-ip - shell: "docker inspect gondul-varnish-test | grep IPAddress | sed 's/[^0-9.]//g' | grep 172.17 | uniq" - register: ip - tags: - - start - - test -- name: workaround to get gondul-front-ip - shell: "docker inspect gondul-front-test | grep IPAddress | sed 's/[^0-9.]//g' | grep 172.17 | uniq" - register: ipfront - tags: - - start - - test - -- name: Display IP - tags: - - start - - test - debug: - msg: "Varnish test is available at http://{{ ip.stdout }}/ uncached ip: http://{{ ipfront.stdout }}/ " - diff --git a/ansible/roles/common/tasks/main.yml b/ansible/roles/common/tasks/main.yml index 4c27c32..619d39f 100644 --- a/ansible/roles/common/tasks/main.yml +++ b/ansible/roles/common/tasks/main.yml @@ -1,15 +1,20 @@ - name: Install basic packages - apt: - name: [ - 'curl', - 'vim', - 'git', - 'iptables-persistent'] - state: present + ansible.builtin.apt: + name: [ + 'curl', + 'vim', + 'git', + 'iptables-persistent'] + state: present - name: Gondul-repo become: true tags: - - git-all - - git-gondul - git: repo={{ git_repo }} dest=/opt/gondul update=no accept_hostkey=yes version={{ git_branch }} + - git-all + - git-gondul + ansible.builtin.git: + repo: "{{ git_repo }}" + dest: /opt/gondul + update: false + accept_hostkey: true + version: "{{ git_branch }}"
\ No newline at end of file diff --git a/ansible/roles/influx/tasks/main.yml b/ansible/roles/influx/tasks/main.yml index fc3571c..8c5e754 100644 --- a/ansible/roles/influx/tasks/main.yml +++ b/ansible/roles/influx/tasks/main.yml @@ -1,23 +1,28 @@ - name: Install apt-packages - apt: - name: 'apt-transport-https' - state: present - -- name: Import InfluxDB GPG signing key - apt_key: url=https://repos.influxdata.com/influxdata-archive_compat.key state=present - -- name: Add InfluxDB repository - apt_repository: repo='deb https://repos.influxdata.com/{{ ansible_distribution | lower }} {{ ansible_distribution_release | lower }} stable' state=present + ansible.builtin.apt: + name: 'apt-transport-https' + state: present - name: Install InfluxDB packages - apt: name=influxdb state=present update_cache=yes + ansible.builtin.apt: + name: influxdb + state: present + update_cache: true - name: Start the InfluxDB service - service: name=influxdb state=started + ansible.builtin.service: + name: influxdb + state: started - name: Wait a few seconds for InfluxDB to start - pause: + ansible.builtin.pause: seconds: 5 +- name: Install influxdb-client + ansible.builtin.apt: + name: influxdb-client + state: present + update_cache: true + - name: Create database - command: /usr/bin/influx -execute 'CREATE DATABASE gondul' + ansible.builtin.command: /usr/bin/influx -execute 'CREATE DATABASE gondul'
\ No newline at end of file diff --git a/ansible/roles/ping/handlers/main.yml b/ansible/roles/ping/handlers/main.yml index 6592e88..d7f132b 100644 --- a/ansible/roles/ping/handlers/main.yml +++ b/ansible/roles/ping/handlers/main.yml @@ -1,3 +1,5 @@ --- -- name: restart gondul-pinger - service: name=gondul-pinger state=restarted +- name: Restart gondul-pinger + ansible.builtin.service: + name: gondul-pinger + state: restarted
\ No newline at end of file diff --git a/ansible/roles/ping/tasks/main.yml b/ansible/roles/ping/tasks/main.yml index cb435d1..b9371ad 100644 --- a/ansible/roles/ping/tasks/main.yml +++ b/ansible/roles/ping/tasks/main.yml @@ -1,10 +1,11 @@ - name: Add systemd service file for gondul-ping - copy: + ansible.builtin.copy: dest: /etc/systemd/system/gondul-pinger.service src: gondul-pinger.service notify: restart gondul-pinger + - name: Enable ping service - systemd: + ansible.builtin.systemd: name: gondul-pinger.service enabled: yes - notify: restart gondul-pinger + notify: restart gondul-pinger
\ No newline at end of file diff --git a/ansible/roles/snmp/tasks/main.yml b/ansible/roles/snmp/tasks/main.yml index 6056a25..85a88cd 100644 --- a/ansible/roles/snmp/tasks/main.yml +++ b/ansible/roles/snmp/tasks/main.yml @@ -1,25 +1,29 @@ - name: Create data directory - file: + ansible.builtin.file: path: /opt/gondul/data state: directory mode: 0755 -- name: register mibdir - stat: + +- name: Register mibdir + ansible.builtin.stat: path: /opt/gondul/data/mibs register: mibdir + - name: Get mibs - command: /opt/gondul/extras/tools/get_mibs.sh + ansible.builtin.command: /opt/gondul/extras/tools/get_mibs.sh args: chdir: /opt/gondul/data/ when: not mibdir.stat.exists notify: restart gondul-snmp + - name: Add systemd service file for gondul-snmp - copy: + ansible.builtin.copy: dest: /etc/systemd/system/gondul-snmp.service src: gondul-snmp.service notify: restart gondul-snmp + - name: Enable snmp service - systemd: + ansible.builtin.systemd: name: gondul-snmp.service enabled: yes - notify: restart gondul-snmp + notify: restart gondul-snmp
\ No newline at end of file diff --git a/ansible/roles/test/tasks/main.yml b/ansible/roles/test/tasks/main.yml deleted file mode 100644 index 798644a..0000000 --- a/ansible/roles/test/tasks/main.yml +++ /dev/null @@ -1,39 +0,0 @@ -- name: test index - tags: - - test - uri: url="http://{{ ip.stdout }}/" - -- name: test public api without data - tags: - - test - uri: - url: "http://{{ ip.stdout }}{{ item }}" - with_items: "{{ simple_urls }}" - -- name: test read api without data - uri: - url: http://{{ ip.stdout }}{{ item }} - user: demo - password: demo - with_items: "{{ read_urls }}" - tags: - - test -- name: Add some switches - tags: - - test - uri: - url: http://{{ ip.stdout }}/api/write/switch-add - method: "POST" - force_basic_auth: true - body_format: json - user: demo - password: demo - body: '[{"mgmt_v4_addr":"127.0.0.1","sysname":"core"},{"distro_name":"core","mgmt_v4_addr":"127.0.0.2","sysname":"distro0"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.3","sysname":"e1-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.4","sysname":"e1-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.5","sysname":"e3-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.6","sysname":"e3-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.7","sysname":"e5-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.8","sysname":"e5-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.9","sysname":"e7-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.10","sysname":"e7-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.11","sysname":"e9-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.12","sysname":"e9-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.14","sysname":"e11-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.15","sysname":"e11-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.16","sysname":"e13-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.17","sysname":"e13-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.18","sysname":"e15-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.19","sysname":"e15-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.20","sysname":"e17-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.21","sysname":"e17-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.22","sysname":"e19-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.23","sysname":"e19-2"},{"distro_name":"core","mgmt_v4_addr":"127.0.0.24","sysname":"distro1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.25","sysname":"e21-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.26","sysname":"e21-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.27","sysname":"e23-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.28","sysname":"e23-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.29","sysname":"e25-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.30","sysname":"e25-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.31","sysname":"e27-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.32","sysname":"e27-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.33","sysname":"e29-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.34","sysname":"e29-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.36","sysname":"e31-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.37","sysname":"e31-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.38","sysname":"e33-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.39","sysname":"e33-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.40","sysname":"e35-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.41","sysname":"e35-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.42","sysname":"e37-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.43","sysname":"e37-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.44","sysname":"e39-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.45","sysname":"e39-2"},{"distro_name":"core","mgmt_v4_addr":"127.0.0.46","sysname":"noc"}]' -- name: test read api after data is added - uri: - url: http://{{ ip.stdout }}{{ item }} - user: demo - password: demo - with_items: "{{ populated_urls }}" - tags: - - test diff --git a/ansible/roles/test/vars/main.yml b/ansible/roles/test/vars/main.yml deleted file mode 100644 index 0bed216..0000000 --- a/ansible/roles/test/vars/main.yml +++ /dev/null @@ -1,18 +0,0 @@ -simple_urls: - - "/api/public/switches" - - "/api/public/switch-state" - - "/api/public/ping" - - "/api/public/location" - - "/api/public/dhcp" - - "/api/public/dhcp-summary" - - "/index.html" - - "/templates/switches.txt" - - "/render/?target=carbon.agents.*.errors" -read_urls: - - "/api/read/oplog" - - "/api/read/snmp" - - "/api/read/switches-management" - - "/api/read/distro-tree" -populated_urls: - - "/api/templates/switches.txt" - diff --git a/ansible/roles/web/handlers/main.yml b/ansible/roles/web/handlers/main.yml index 77d887b..e9f8457 100644 --- a/ansible/roles/web/handlers/main.yml +++ b/ansible/roles/web/handlers/main.yml @@ -1,23 +1,22 @@ --- -- name: restart apache - systemd: +- name: Restart apache + ansible.builtin.systemd: state: restarted - daemon_reload: yes + daemon_reload: true name: apache2 -- name: restart varnish - systemd: +- name: Restart varnish + ansible.builtin.systemd: state: restarted - daemon_reload: yes + daemon_reload: true name: varnish -- name: restart gondul-template - systemd: +- name: Restart gondul-template + ansible.builtin.systemd: state: restarted - daemon_reload: yes + daemon_reload: true name: gondul-template -- name: reload systemd - systemd: - daemon_reload: yes - +- name: Reload systemd + ansible.builtin.systemd: + daemon_reload: true
\ No newline at end of file diff --git a/ansible/roles/web/tasks/main.yml b/ansible/roles/web/tasks/main.yml index 599035d..a444989 100644 --- a/ansible/roles/web/tasks/main.yml +++ b/ansible/roles/web/tasks/main.yml @@ -1,103 +1,98 @@ - name: Install front-packages - apt: - name: [ - 'libcapture-tiny-perl', - 'libcommon-sense-perl', - 'libdata-dumper-simple-perl', - 'libdbd-pg-perl', - 'libdbi-perl', - 'libdigest-perl', - 'libgd-perl', - 'libgeo-ip-perl', - 'libhtml-parser-perl', - 'libhtml-template-perl', - 'libjson-perl', - 'libjson-xs-perl', - 'libnetaddr-ip-perl', - 'libnet-cidr-perl', - 'libnet-ip-perl', - 'libnet-oping-perl', - 'libnet-rawip-perl', - 'libsnmp-perl', - 'libsocket6-perl', - 'libsocket-perl', - 'libswitch-perl', - 'libtimedate-perl', - 'perl', - 'perl-base', - 'perl-modules', - 'libfreezethaw-perl', - 'apache2', - 'libxml2-dev', - 'build-essential', - 'cpanminus', - 'apt-transport-https', - 'python3-netaddr', - 'python3-flask'] - state: present + ansible.builtin.apt: + name: [ + 'libcapture-tiny-perl', + 'libcommon-sense-perl', + 'libdata-dumper-simple-perl', + 'libdbd-pg-perl', + 'libdbi-perl', + 'libdigest-perl', + 'libgd-perl', + 'libgeo-ip-perl', + 'libhtml-parser-perl', + 'libhtml-template-perl', + 'libjson-perl', + 'libjson-xs-perl', + 'libnetaddr-ip-perl', + 'libnet-cidr-perl', + 'libnet-ip-perl', + 'libnet-oping-perl', + 'libnet-rawip-perl', + 'libsnmp-perl', + 'libsocket6-perl', + 'libsocket-perl', + 'libswitch-perl', + 'libtimedate-perl', + 'perl', + 'perl-base', + 'perl-modules', + 'libfreezethaw-perl', + 'apache2', + 'libxml2-dev', + 'build-essential', + 'cpanminus', + 'apt-transport-https', + 'python3-netaddr', + 'python3-flask'] + state: present - name: Install InfluxDB module - cpanm: + community.general.cpanm: name: AnyEvent::InfluxDB - name: Make apache listen on port 8080 - lineinfile: dest=/etc/apache2/ports.conf regexp="^Listen 80" line="Listen 8080" state=present + ansible.builtin.lineinfile: dest=/etc/apache2/ports.conf regexp="^Listen 80" line="Listen 8080" state=present notify: restart apache -- apache2_module: +- name: Add Apache2 Module + ansible.builtin.apache2_module: state: present name: cgid notify: restart apache - name: Enable gondul-config - copy: - dest: /etc/apache2/sites-enabled/gondul.conf - src: apache-virtualhost.conf + ansible.builtin.copy: + dest: /etc/apache2/sites-enabled/gondul.conf + src: apache-virtualhost.conf notify: restart apache -- command: a2dissite 000-default +- name: Disable default Apache site + ansible.builtin.command: a2dissite 000-default ignore_errors: true notify: restart apache -- name: Add packagecloud.io Varnish apt key. - apt_key: - url: https://packagecloud.io/varnishcache/varnish60lts/gpgkey - state: present - -- name: Add packagecloud.io Varnish apt repository. - apt_repository: - repo: "deb https://packagecloud.io/varnishcache/varnish60lts/{{ ansible_distribution | lower }}/ {{ ansible_distribution_release }} main" - state: present - - name: Ensure Varnish is installed. - apt: + ansible.builtin.apt: name: "varnish" state: present - name: Ensure folder varnish.service.d exists - file: path=/etc/systemd/system/varnish.service.d/ state=directory mode=0755 + ansible.builtin.file: + path: /etc/systemd/system/varnish.service.d/ + state: directory + mode: 0755 - name: Change varnish service.d - copy: - dest: /etc/systemd/system/varnish.service.d/customexec.conf - src: varnish.service + ansible.builtin.copy: + dest: /etc/systemd/system/varnish.service.d/customexec.conf + src: varnish.service notify: - reload systemd - name: Copy varnish-acl config - copy: - dest: /etc/varnish/auth.vcl - src: auth.vcl + ansible.builtin.copy: + dest: /etc/varnish/auth.vcl + src: auth.vcl notify: restart varnish - name: Copy varnish config - copy: - dest: /etc/varnish/default.vcl - src: varnish.vcl + ansible.builtin.copy: + dest: /etc/varnish/default.vcl + src: varnish.vcl notify: restart varnish -- name: add systemd service file for gondul-template - copy: +- name: Add systemd service file for gondul-template + ansible.builtin.copy: dest: /etc/systemd/system/gondul-template.service src: gondul-template.service - notify: restart gondul-template + notify: restart gondul-template
\ No newline at end of file diff --git a/ansible/site.yml b/ansible/site.yml index ca4554d..d5d4734 100644 --- a/ansible/site.yml +++ b/ansible/site.yml @@ -1,27 +1,38 @@ --- -- hosts: all +- name: Common role + hosts: all roles: - common vars: git_repo: https://github.com/gathering/gondul.git git_branch: master -- hosts: postgres + +- name: Postgres Install + hosts: postgres become: true roles: - postgres -- hosts: web + +- name: Web Install + hosts: web become: true roles: - web -- hosts: influx + +- name: Influx Install + hosts: influx become: true roles: - influx -- hosts: ping + +- name: Ping Install + hosts: ping become: true roles: - ping -- hosts: snmp + +- name: SNMP Install + hosts: snmp become: true roles: - - snmp + - snmp
\ No newline at end of file |