From e3639cc94ca84a6f9f48c42242cb1aa8fc318ebf Mon Sep 17 00:00:00 2001 From: Chl Date: Tue, 29 Sep 2020 02:57:15 +0200 Subject: [PATCH] Initial commit --- .gitignore | 3 + .gitmodules | 3 + README.md | 126 +++++++++++++++++ ansible.cfg | 32 +++++ inventory.yml | 8 ++ roles/mapserver/files/basemaps | 1 + roles/mapserver/handlers/main.yml | 5 + roles/mapserver/tasks/10_package-install.yml | 6 + .../mapserver/tasks/20_database-creation.yml | 25 ++++ roles/mapserver/tasks/30_basemaps.yml | 66 +++++++++ roles/mapserver/tasks/40_imposm.yml | 49 +++++++ .../tasks/50_mapcache-and-apache.yml | 75 +++++++++++ roles/mapserver/tasks/main.yml | 38 ++++++ roles/mapserver/templates/apache2/vhost.j2 | 32 +++++ .../mapserver/templates/basemaps/Makefile.j2 | 127 ++++++++++++++++++ .../mapcache/mapcache.xml.Debian-10.j2 | 62 +++++++++ roles/mapserver/vars/Debian-10.yml | 16 +++ site.yml | 6 + 18 files changed, 680 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 README.md create mode 100644 ansible.cfg create mode 100644 inventory.yml create mode 160000 roles/mapserver/files/basemaps create mode 100644 roles/mapserver/handlers/main.yml create mode 100644 roles/mapserver/tasks/10_package-install.yml create mode 100644 roles/mapserver/tasks/20_database-creation.yml create mode 100644 roles/mapserver/tasks/30_basemaps.yml create mode 100644 roles/mapserver/tasks/40_imposm.yml create mode 100644 roles/mapserver/tasks/50_mapcache-and-apache.yml create mode 100644 roles/mapserver/tasks/main.yml create mode 100644 roles/mapserver/templates/apache2/vhost.j2 create mode 100644 roles/mapserver/templates/basemaps/Makefile.j2 create mode 100644 roles/mapserver/templates/mapcache/mapcache.xml.Debian-10.j2 create mode 100644 roles/mapserver/vars/Debian-10.yml create mode 100644 site.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aab1b96 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/*.zip +/*.osm.pbf +/*vault* diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..8692306 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "roles/mapserver/files/basemaps"] + path = roles/mapserver/files/basemaps + url = https://github.com/mapserver/basemaps diff --git a/README.md b/README.md new file mode 100644 index 0000000..08cdf42 --- /dev/null +++ b/README.md @@ -0,0 +1,126 @@ +**Important : this playbook is quick'n dirty and work in progress. Carefully review before using it.** + +This Ansible playbook aims at setting a MapServer tile server on a +Debian 10 Buster, inspired by +https://github.com/mapserver/mapserver/wiki/Rendering-OSM-data-on-Ubuntu-12.04 +and https://github.com/mapserver/basemaps. + +Here is a rough view of what will be set upĀ (note: even with the following little import, be sure to have 3-4GB of available storage): + +``` +# Install PostgreSQL + PostGIS, Apache, the MapServer CGI, imposm +apt install postgis apache2 mapserver-bin cgi-mapserver libapache2-mod-mapcache imposm +# ...and some dev tools for the basemap +apt install make unzip wget git + +# Create a dedicated database user with its own database +# (you can harden the password but remember to edit the basemap's Makefile) +# (unfortunately, I didn't manage to configure all the tools to use the unix socket. Ping me if you succeeded!) +su -c 'psql -c "CREATE USER osm WITH PASSWORD '"'"'osm'"'"';"' postgres +su -c "psql -c 'CREATE DATABASE osm WITH OWNER osm;'" postgres +su -c "psql -c 'CREATE EXTENSION postgis;' osm" postgres + +# Download or clone an OSM basemap +# (in case of trouble, this tuto was tested with the commit 0c21924a1b1d20cea3acf35fc46256d019877338) +mkdir -p /srv/osm +cd /srv/osm +git clone "https://github.com/mapserver/basemaps" + +# Initial (only needed once) download of worldwide shapefiles (~750MB) +# (the two zip files can be copied on following hosts to avoid the download) +cd basemaps/data +make + +# Generation +# (here, you can customize the Makefile. For example the style (default, google, bing) and the database connection) +cd .. +make + +# Finally, import data... +mkdir /srv/osm/imposm +cd /srv/osm/imposm + +# Manually download some small .pbf files as a test +wget https://download.geofabrik.de/australia-oceania/new-caledonia-latest.osm.pbf +wget https://download.geofabrik.de/europe/iceland-latest.osm.pbf +# ...and import in PostGIS +imposm --mapping-file=/srv/osm/basemaps/imposm-mapping.py --proj=EPSG:3857 --read new-caledonia-latest.osm.pbf +imposm --mapping-file=/srv/osm/basemaps/imposm-mapping.py --proj=EPSG:3857 --read --merge-cache iceland-latest.osm.pbf +imposm --mapping-file=/srv/osm/basemaps/imposm-mapping.py --proj=EPSG:3857 --connection=postgis://osm:osm@localhost:5432/osm --write +imposm --mapping-file=/srv/osm/basemaps/imposm-mapping.py --proj=EPSG:3857 --connection=postgis://osm:osm@localhost:5432/osm --optimize +imposm --mapping-file=/srv/osm/basemaps/imposm-mapping.py --proj=EPSG:3857 --connection=postgis://osm:osm@localhost:5432/osm --deploy-production-tables + +# Configure Apache, MapServer and MapCache +mkdir /srv/osm/mapcache +cp -i /usr/share/doc/libapache2-mod-mapcache/examples/mapcache.xml /srv/osm/mapcache/ +# Change layer to 'default' and add a pointer to the basemap, in mapcache > source > getmap > params +# Remember to adapt 'osm-default.map' if you changed the style in the basemap's Makefile (google, bing) +sed -i 's#^\([[:space:]]\+\).*#\1default\n\1/srv/osm/basemaps/osm-default.map#' mapcache.xml +# Modify the url to point to the local CGI +sed -i 's#.*#http://localhost/cgi-bin/mapserv?#' /srv/osm/mapcache/mapcache.xml +# And configure Apache +cd /etc/apache2 +a2enmod cgi +a2disconf serve-cgi-bin.conf +sed -i 's/Require all granted/Require local/' conf-available/serve-cgi-bin.conf +sed -i 's%#Include conf-available/serve-cgi-bin.conf%Include conf-available/serve-cgi-bin.conf\n\tMapCacheAlias /mapcache "/srv/osm/mapcache/mapcache.xml"%' sites-available/000-default.conf +apache2ctl configtest +service apache2 restart +``` + +You can test it at http://your.server.name.tld/mapcache/demo/ + +## Back to Ansible + +Most of the configuration should be available in the inventory. + +It is launched usually like this : `ansible-playbook site.yml` + +If you want to override the passwords within a vaultĀ : +``` +ansible-vault create vault.yml +# vault.yml example (take variables' names from inventory, vars, ...) : +# --- +# password: mypass +ansible-playbook -e @vault.yml --ask-vault-pass site.yml +``` + +## Prerequisites + +### Prerequisites for the hosts +Hosts should be accessible via SSH as the root user (else, add the usual +`remote_user`/`become` instructions in ansible.cfg) and with the Python +prerequisite of Ansible (usually `python-minimal`). + +Only tested on Debian 10 amd64 so far, with Ansible 2.7.7. + +Note : to test or to limit to one particular host : +``` +ansible foo.bar.com -m ping +ansible-playbook -l foo.bar.com -v -C -D site.yml +``` + +## Directory layout + +We follow (more or less) the recommendations of +https://docs.ansible.com/ansible/latest/user_guide/playbooks_best_practices.html +with : +- `site.yml` : master playbook +- `ansible.cfg` and `inventory.yml` : the first one set up some default configurations and introduce the second one : the inventory. +- `roles/common/`, `roles/fooapp/` : the roles with their tree `tasks/main.yml`, `files/`, `handlers/main.yml`, ... +- `group_vars/group1.yml` and `host_vars/hostname1.yml` : variables dedicated to a group or a host respectively. + +Note : contrary to some recommendations, I prefer to set some variables in +the inventory instead of `host_vars` and `group_vars`. For a small playbook +like this one, it seems acceptable and it makes it easier to look where to +adapt. + +## TODO + +- better cross-platform compatibility +- use osmosis ? Said to be better than imposm (warning: heavy Java dependencies...) +- check disk space ? + +## License + +[CC-0](https://creativecommons.org/publicdomain/zero/1.0/) diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..49dc476 --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,32 @@ +# config file for ansible -- http://ansible.com/ +# ============================================== + +# nearly all parameters can be overridden in ansible-playbook +# or with command line flags. ansible will read ANSIBLE_CONFIG, +# ansible.cfg in the current working directory, .ansible.cfg in +# the home directory or /etc/ansible/ansible.cfg, whichever it +# finds first + +[defaults] + +# some basic default values... + +inventory = ./inventory.yml +#remote_tmp = /tmp/.ansible +remote_user = root +transport = ssh +remote_port = 22 +# We try not to load the hypervisor +#forks = 2 + +# For the time being, we don't trigger handlers (for example +# restart SSH after modifying its config) when an error +# happened. +# It is the default Ansible behaviour but I prefer to explicitly +# set it here in case a change is needed later. +force_handlers = False + +#filter_plugins = ./plugins/filter_plugins + +#[privilege_escalation] +#become = True diff --git a/inventory.yml b/inventory.yml new file mode 100644 index 0000000..b3e9451 --- /dev/null +++ b/inventory.yml @@ -0,0 +1,8 @@ +all: + hosts: + mapserver1.xlii.si: + basemaps_style: google + + vars: + # Default basemaps style + basemaps_style: default diff --git a/roles/mapserver/files/basemaps b/roles/mapserver/files/basemaps new file mode 160000 index 0000000..0c21924 --- /dev/null +++ b/roles/mapserver/files/basemaps @@ -0,0 +1 @@ +Subproject commit 0c21924a1b1d20cea3acf35fc46256d019877338 diff --git a/roles/mapserver/handlers/main.yml b/roles/mapserver/handlers/main.yml new file mode 100644 index 0000000..3f75358 --- /dev/null +++ b/roles/mapserver/handlers/main.yml @@ -0,0 +1,5 @@ +--- + +- name: handlerRestartApache + become: yes + service: name=apache2 state=restarted enabled=yes diff --git a/roles/mapserver/tasks/10_package-install.yml b/roles/mapserver/tasks/10_package-install.yml new file mode 100644 index 0000000..0913c80 --- /dev/null +++ b/roles/mapserver/tasks/10_package-install.yml @@ -0,0 +1,6 @@ +--- + +- name: Install packages + apt: + name: "{{ packages_list }}" + when: ansible_os_family == "Debian" diff --git a/roles/mapserver/tasks/20_database-creation.yml b/roles/mapserver/tasks/20_database-creation.yml new file mode 100644 index 0000000..0d41fcf --- /dev/null +++ b/roles/mapserver/tasks/20_database-creation.yml @@ -0,0 +1,25 @@ +--- + +- name: Create database user + postgresql_user: + name: osm + password: osm + become: yes + become_user: postgres + become_method: su + +- name: Create database + postgresql_db: + name: osm + owner: osm + become: yes + become_user: postgres + become_method: su + +- name: Add PostGIS extension to database + postgresql_ext: + db: osm + name: postgis + become: yes + become_user: postgres + become_method: su diff --git a/roles/mapserver/tasks/30_basemaps.yml b/roles/mapserver/tasks/30_basemaps.yml new file mode 100644 index 0000000..adaad1a --- /dev/null +++ b/roles/mapserver/tasks/30_basemaps.yml @@ -0,0 +1,66 @@ +--- + +# We offer the possibility to host the basemaps repo in files/basemaps +# as a git submodule. +# note : currently, if this method is used, any remote modification is erased. +- name: Check if the basemaps repo has been cloned in files/ + run_once: true + local_action: stat path={{ role_path }}/files/basemaps/.git + register: basemaps_locally_available + +- name: Copy local basemaps to host + copy: + src: "{{ role_path}}/files/basemaps/" + dest: /srv/osm/basemaps/ + when: basemaps_locally_available.stat.exists + +- name: Clone basemaps + git: + repo: https://github.com/mapserver/basemaps + dest: /srv/osm/basemaps + when: basemaps_locally_available.stat.exists != True + + +# This is usually a one shot. Unless no .zip file is in /data, we skip the whole thing. +# Simply remove the .zip files in basemaps/data/ if you need to refresh it. +- name: Check if basemaps/data has been initialized + find: + paths: /srv/osm/basemaps/data + patterns: '*.zip' + register: basemaps_data_zip_list + +- name: Upload the local shapefiles, if available, to save some bandwidth to the OSM project + copy: + src: "{{ item }}" + dest: /srv/osm/basemaps/data/ + with_fileglob: + # Let's get to the root of the playbook + - "../../../*land-polygons*.zip" + - "*land-polygons*.zip" + when: basemaps_data_zip_list.matched == 0 + +- name: Initialize basemaps/data + command: make + args: + chdir: /srv/osm/basemaps/data/ + when: basemaps_data_zip_list.matched == 0 + + +# Customize Makefile +- name: Customize basemaps Makefile + template: + src: "{{ item }}" + dest: /srv/osm/basemaps/Makefile + backup: no + with_first_found: + - files: + - "basemaps/Makefile.{{ ansible_fqdn }}.j2" + - "basemaps/Makefile.j2" + skip: true + register: tmp + +- name: Generate basemaps + # It seems Make doesn't see a makefile's modification worth a rebuild, so we force it a bit. + command: "{{ tmp.changed | ternary('make --always-make', 'make') }}" + args: + chdir: /srv/osm/basemaps/ diff --git a/roles/mapserver/tasks/40_imposm.yml b/roles/mapserver/tasks/40_imposm.yml new file mode 100644 index 0000000..54d0569 --- /dev/null +++ b/roles/mapserver/tasks/40_imposm.yml @@ -0,0 +1,49 @@ +--- + +# Upload .osm.pbf files found at the root of the playbook or in the /files role's subfolder +- name: Imposm - Upload any local .osm.pbf files + copy: + src: "{{ item }}" + dest: /srv/osm/imposm/ + with_fileglob: + # Let's get to the root of the playbook + - "../../../*.osm.pbf" + - "*.osm.pbf" + +# If the .osm.pbf files are not newer than the cache, we skip the whole thing. +- name: Imposm - Check if there is already a cache + stat: + path: /srv/osm/imposm/imposm_relations.cache + register: tmp +- name: Imposm - List pbf files waiting to be imported + command: find /srv/osm/imposm -iname '*.osm.pbf' {{ tmp.stat.exists | ternary('-newer imposm_relations.cache', '') }} + args: + chdir: /srv/osm/imposm + register: imposm_pbf_list + changed_when: False + check_mode: no + +- name: Imposm - Import each new files + command: imposm --mapping-file=/srv/osm/basemaps/imposm-mapping.py --proj=EPSG:3857 --read --merge-cache {{ item|quote }} + args: + chdir: /srv/osm/imposm + loop: "{{ imposm_pbf_list.stdout_lines }}" + +- name: Imposm - Write to database + command: imposm --mapping-file=/srv/osm/basemaps/imposm-mapping.py --proj=EPSG:3857 --connection=postgis://osm:osm@localhost:5432/osm --write + args: + chdir: /srv/osm/imposm + when: imposm_pbf_list.stdout_lines + +- name: Imposm - Optimze database + command: imposm --mapping-file=/srv/osm/basemaps/imposm-mapping.py --proj=EPSG:3857 --connection=postgis://osm:osm@localhost:5432/osm --optimize + args: + chdir: /srv/osm/imposm + when: imposm_pbf_list.stdout_lines + +- name: Imposm - Switch new data to production + command: imposm --mapping-file=/srv/osm/basemaps/imposm-mapping.py --proj=EPSG:3857 --connection=postgis://osm:osm@localhost:5432/osm --deploy-production-tables + args: + chdir: /srv/osm/imposm + when: imposm_pbf_list.stdout_lines + diff --git a/roles/mapserver/tasks/50_mapcache-and-apache.yml b/roles/mapserver/tasks/50_mapcache-and-apache.yml new file mode 100644 index 0000000..dd302a8 --- /dev/null +++ b/roles/mapserver/tasks/50_mapcache-and-apache.yml @@ -0,0 +1,75 @@ +--- + + +# MapCache +- name: Configure MapCache + template: + src: "{{ item }}" + dest: /srv/osm/mapcache/mapcache.xml + backup: no + with_first_found: + - "mapcache/mapcache.xml.{{ ansible_fqdn }}.j2" + - "mapcache/mapcache.xml.{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.j2" + - "mapcache/mapcache.xml.{{ ansible_distribution }}.j2" + - "mapcache/mapcache.xml.j2" + notify: + - handlerRestartApache + + +# Apache customizations +- name: Apache - Activate CGI module + apache2_module: + state: present + name: cgid + notify: + - handlerRestartApache + +# Kinda paranoiac but I prefer the CGI not being freely accessible +- name: Apache - Restrict access to CGI + lineinfile: + path: /etc/apache2/conf-available/serve-cgi-bin.conf + regexp: '^(\s+)Require ' + line: '\1Require local' + backrefs: yes + notify: + - handlerRestartApache + +# We gather some extra data for the vhost template +- name: Apache - Set a fact about whether SSL is enabled or not - 1 + apache2_module: + state: present + name: ssl + check_mode: yes + register: tmp +- name: Apache - Set a fact about whether SSL is enabled or not - 2 + set_fact: + apache_module_ssl_enabled: "{{ not tmp.changed }}" + +- name: Apache - Set up vhost + template: + src: "{{ item }}" + dest: "{{ mapcache_vhost_filename }}" + backup: no + with_first_found: + - "apache2/vhost.{{ ansible_fqdn }}.j2" + - "apache2/vhost.{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.j2" + - "apache2/vhost.{{ ansible_distribution }}.j2" + - "apache2/vhost.j2" + notify: + - handlerRestartApache + +# We try not to generate a 'changed' when using a2ensite, so we check beforehand. +- name: Apache - Check if vhost is enabled + command: find -L /etc/apache2/sites-enabled/ -samefile {{ mapcache_vhost_filename | quote }} + register: tmp + changed_when: False + check_mode: no +- name: Apache - Enable vhost + command: a2ensite {{ mapcache_vhost_filename | basename | quote }} + when: not tmp.stdout + notify: + - handlerRestartApache + +- name: Apache - Check config + command: apache2ctl configtest + changed_when: False diff --git a/roles/mapserver/tasks/main.yml b/roles/mapserver/tasks/main.yml new file mode 100644 index 0000000..908c9a5 --- /dev/null +++ b/roles/mapserver/tasks/main.yml @@ -0,0 +1,38 @@ +--- + +- name: Gather os specific variables + block: + - include_vars: "{{ item }}" + with_first_found: # Files are in 'vars/' subdirectory and contain a one level dictionary 'var: value' + - "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml" + - "{{ ansible_distribution }}.yml" + - "{{ ansible_os_family }}.yml" + #- "defaults.yml" # No defaults for this role at the moment. + rescue: + - fail: + msg: "Unexpected OS/Distribution. Create and fill vars/{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml" + +# Dedicated directories +- name: Imposm dedicated directory + file: + path: /srv/osm/imposm + state: directory +- name: MapCache dedicated directory + file: + path: /srv/osm/mapcache + state: directory + +# Packages installation +- import_tasks: 10_package-install.yml + +# Database creation +- import_tasks: 20_database-creation.yml + +# Retrieve the OSM basemaps +- import_tasks: 30_basemaps.yml + +# Import with imposm +- import_tasks: 40_imposm.yml + +# Mapcache and Apache +- import_tasks: 50_mapcache-and-apache.yml diff --git a/roles/mapserver/templates/apache2/vhost.j2 b/roles/mapserver/templates/apache2/vhost.j2 new file mode 100644 index 0000000..cf9e92b --- /dev/null +++ b/roles/mapserver/templates/apache2/vhost.j2 @@ -0,0 +1,32 @@ + + # The ServerName directive sets the request scheme, hostname and port that + # the server uses to identify itself. This is used when creating + # redirection URLs. In the context of virtual hosts, the ServerName + # specifies what hostname must appear in the request's Host: header to + # match this virtual host. For the default virtual host (this file) this + # value is not decisive as it is used as a last resort host regardless. + # However, you must set it for any further virtual host explicitly. + #ServerName www.example.com + + ServerAdmin webmaster@localhost + DocumentRoot /var/www/html + + # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, + # error, crit, alert, emerg. + # It is also possible to configure the loglevel for particular + # modules, e.g. + #LogLevel info ssl:warn + + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined + + # For most configuration files from conf-available/, which are + # enabled or disabled at a global level, it is possible to + # include a line for only one particular virtual host. For example the + # following line enables the CGI configuration for this host only + # after it has been globally disabled with "a2disconf". + #Include conf-available/serve-cgi-bin.conf + MapCacheAlias /mapcache "/srv/osm/mapcache/mapcache.xml" + + +# vim: syntax=apache ts=4 sw=4 sts=4 sr noet diff --git a/roles/mapserver/templates/basemaps/Makefile.j2 b/roles/mapserver/templates/basemaps/Makefile.j2 new file mode 100644 index 0000000..53c553d --- /dev/null +++ b/roles/mapserver/templates/basemaps/Makefile.j2 @@ -0,0 +1,127 @@ +UNAME := $(shell uname) + +ifeq ($(UNAME), Darwin) +SED=sed -i "" +else +SED=sed -i +endif + +CPP=gcc -E -x c +#if the preprocessor fails for some reason, try replacing this with "cpp" on linux, or "cpp-4.2" on darwin (not available starting with mountain lion) + + +OSM_PREFIX?=osm_ +OSM_NAME_COLUMN?=name +#OSM_SRID?=4326 +#OSM_UNITS?=dd +#OSM_EXTENT?=-180 -90 180 90 +OSM_SRID?=3857 +OSM_UNITS?=meters +OSM_DB_CONNECTION?=host=localhost dbname=osm user=osm password=osm port=5432 +OSM_EXTENT?=-20000000 -20000000 20000000 20000000 +OSM_FORCE_POSTGIS_EXTENT?=0 +OSM_WMS_SRS?=EPSG:900913 EPSG:4326 EPSG:3857 EPSG:2154 EPSG:310642901 EPSG:4171 EPSG:310024802 EPSG:310915814 EPSG:310486805 EPSG:310702807 EPSG:310700806 EPSG:310547809 EPSG:310706808 EPSG:310642810 EPSG:310642801 EPSG:310642812 EPSG:310032811 EPSG:310642813 EPSG:2986 +DEBUG?=1 +LAYERDEBUG?=1 +PROJ_LIB?=`pwd` +STYLE?={{ basemaps_style }} +#can also use google or bing + +template=osmbase.map + +includes=land.map landusage.map borders.map highways.map places.map \ + generated/$(STYLE)style.msinc \ + generated/$(STYLE)level0.msinc generated/$(STYLE)level1.msinc generated/$(STYLE)level2.msinc generated/$(STYLE)level3.msinc \ + generated/$(STYLE)level4.msinc generated/$(STYLE)level5.msinc generated/$(STYLE)level6.msinc generated/$(STYLE)level7.msinc \ + generated/$(STYLE)level8.msinc generated/$(STYLE)level9.msinc generated/$(STYLE)level10.msinc generated/$(STYLE)level11.msinc \ + generated/$(STYLE)level12.msinc generated/$(STYLE)level13.msinc generated/$(STYLE)level14.msinc generated/$(STYLE)level15.msinc \ + generated/$(STYLE)level16.msinc generated/$(STYLE)level17.msinc generated/$(STYLE)level18.msinc + + + +mapfile=osm-$(STYLE).map + +all:$(mapfile) boundaries.sql + +generated/$(STYLE)style.msinc: generate_style.py + python generate_style.py -s $(STYLE) -g > $@ + +generated/$(STYLE)level0.msinc: generate_style.py + python generate_style.py -s $(STYLE) -l 0 > $@ + +generated/$(STYLE)level1.msinc: generate_style.py + python generate_style.py -s $(STYLE) -l 1 > $@ + +generated/$(STYLE)level2.msinc: generate_style.py + python generate_style.py -s $(STYLE) -l 2 > $@ + +generated/$(STYLE)level3.msinc: generate_style.py + python generate_style.py -s $(STYLE) -l 3 > $@ + +generated/$(STYLE)level4.msinc: generate_style.py + python generate_style.py -s $(STYLE) -l 4 > $@ + +generated/$(STYLE)level5.msinc: generate_style.py + python generate_style.py -s $(STYLE) -l 5 > $@ + +generated/$(STYLE)level6.msinc: generate_style.py + python generate_style.py -s $(STYLE) -l 6 > $@ + +generated/$(STYLE)level7.msinc: generate_style.py + python generate_style.py -s $(STYLE) -l 7 > $@ + +generated/$(STYLE)level8.msinc: generate_style.py + python generate_style.py -s $(STYLE) -l 8 > $@ + +generated/$(STYLE)level9.msinc: generate_style.py + python generate_style.py -s $(STYLE) -l 9 > $@ + +generated/$(STYLE)level10.msinc: generate_style.py + python generate_style.py -s $(STYLE) -l 10 > $@ + +generated/$(STYLE)level11.msinc: generate_style.py + python generate_style.py -s $(STYLE) -l 11 > $@ + +generated/$(STYLE)level12.msinc: generate_style.py + python generate_style.py -s $(STYLE) -l 12 > $@ + +generated/$(STYLE)level13.msinc: generate_style.py + python generate_style.py -s $(STYLE) -l 13 > $@ + +generated/$(STYLE)level14.msinc: generate_style.py + python generate_style.py -s $(STYLE) -l 14 > $@ + +generated/$(STYLE)level15.msinc: generate_style.py + python generate_style.py -s $(STYLE) -l 15 > $@ + +generated/$(STYLE)level16.msinc: generate_style.py + python generate_style.py -s $(STYLE) -l 16 > $@ + +generated/$(STYLE)level17.msinc: generate_style.py + python generate_style.py -s $(STYLE) -l 17 > $@ + +generated/$(STYLE)level18.msinc: generate_style.py + python generate_style.py -s $(STYLE) -l 18 > $@ + +$(mapfile):$(template) $(includes) + $(CPP) -D_debug=$(DEBUG) -D_layerdebug=$(LAYERDEBUG) -DOSM_PREFIX=$(OSM_PREFIX) -DOSM_SRID=$(OSM_SRID) -DOSM_FORCE_POSTGIS_EXTENT=$(OSM_FORCE_POSTGIS_EXTENT) -P -o $(mapfile) $(template) -DTHEME=$(STYLE) -D_proj_lib=\"$(PROJ_LIB)\" -Igenerated + $(SED) 's/##.*$$//g' $(mapfile) + $(SED) '/^ *$$/d' $(mapfile) + $(SED) -e 's/OSM_PREFIX_/$(OSM_PREFIX)/g' $(mapfile) + $(SED) -e 's/OSM_SRID/$(OSM_SRID)/g' $(mapfile) + $(SED) -e 's/OSM_UNITS/$(OSM_UNITS)/g' $(mapfile) + $(SED) -e 's/OSM_EXTENT/$(OSM_EXTENT)/g' $(mapfile) + $(SED) -e 's/OSM_WMS_SRS/$(OSM_WMS_SRS)/g' $(mapfile) + $(SED) -e 's/OSM_NAME_COLUMN/$(OSM_NAME_COLUMN)/g' $(mapfile) + $(SED) -e 's/OSM_DB_CONNECTION/$(OSM_DB_CONNECTION)/g' $(mapfile) + +boundaries.sql: boundaries.sql.in + cp -f $< $@ + $(SED) -e 's/OSM_PREFIX_/$(OSM_PREFIX)/g' $@ + +clean: + rm -f generated/* + +.PHONY: data +data: + cd data; $(MAKE) $(MFLAGS) diff --git a/roles/mapserver/templates/mapcache/mapcache.xml.Debian-10.j2 b/roles/mapserver/templates/mapcache/mapcache.xml.Debian-10.j2 new file mode 100644 index 0000000..3bed3c9 --- /dev/null +++ b/roles/mapserver/templates/mapcache/mapcache.xml.Debian-10.j2 @@ -0,0 +1,62 @@ + + + + + + + /tmp + + + + /tmp/{tileset}-{z}-{grid}.db + + + + + + + image/png + default + /srv/osm/basemaps/osm-{{ basemaps_style }}.map + + + + + http://localhost/cgi-bin/mapserv? + + + + + vmap0 + sqlite + WGS84 + GoogleMapsCompatible + PNG + 5 5 + 10 + 3600 + + + JPEG + + + assemble + bilinear + JPEG + 4096 + + + + + + + + + + report + + /tmp + 300 + + + diff --git a/roles/mapserver/vars/Debian-10.yml b/roles/mapserver/vars/Debian-10.yml new file mode 100644 index 0000000..d3b8c14 --- /dev/null +++ b/roles/mapserver/vars/Debian-10.yml @@ -0,0 +1,16 @@ +--- + +# basemaps needs make unzip wget git +packages_list: + - apache2 + - cgi-mapserver + - git + - imposm + - libapache2-mod-mapcache + - make + - mapserver-bin + - postgis + - unzip + - wget + +mapcache_vhost_filename: /etc/apache2/sites-available/000-default.conf diff --git a/site.yml b/site.yml new file mode 100644 index 0000000..b880f93 --- /dev/null +++ b/site.yml @@ -0,0 +1,6 @@ +--- + +- name: "Role for OSM/MapServer/Postgis installation and management" + hosts: all + roles: + - mapserver