Initial commit

This commit is contained in:
Chl 2020-09-29 02:57:15 +02:00
commit e3639cc94c
18 changed files with 680 additions and 0 deletions

@ -0,0 +1 @@
Subproject commit 0c21924a1b1d20cea3acf35fc46256d019877338

View file

@ -0,0 +1,5 @@
---
- name: handlerRestartApache
become: yes
service: name=apache2 state=restarted enabled=yes

View file

@ -0,0 +1,6 @@
---
- name: Install packages
apt:
name: "{{ packages_list }}"
when: ansible_os_family == "Debian"

View file

@ -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

View file

@ -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/

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,32 @@
<VirtualHost *:80>
# 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"
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

View file

@ -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)

View file

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- see the accompanying mapcache.xml.sample for a fully commented configuration file -->
<mapcache>
<cache name="disk" type="disk">
<base>/tmp</base>
<symlink_blank/>
</cache>
<cache name="sqlite" type="sqlite3">
<dbfile>/tmp/{tileset}-{z}-{grid}.db</dbfile>
<detect_blank/>
</cache>
<source name="vmap0" type="wms">
<getmap>
<params>
<FORMAT>image/png</FORMAT>
<LAYERS>default</LAYERS>
<MAP>/srv/osm/basemaps/osm-{{ basemaps_style }}.map</MAP>
</params>
</getmap>
<http>
<url>http://localhost/cgi-bin/mapserv?</url>
</http>
</source>
<tileset name="test">
<source>vmap0</source>
<cache>sqlite</cache>
<grid>WGS84</grid>
<grid>GoogleMapsCompatible</grid>
<format>PNG</format>
<metatile>5 5</metatile>
<metabuffer>10</metabuffer>
<expires>3600</expires>
</tileset>
<default_format>JPEG</default_format>
<service type="wms" enabled="true">
<full_wms>assemble</full_wms>
<resample_mode>bilinear</resample_mode>
<format>JPEG</format>
<maxsize>4096</maxsize>
</service>
<service type="wmts" enabled="true"/>
<service type="tms" enabled="true"/>
<service type="kml" enabled="true"/>
<service type="gmaps" enabled="true"/>
<service type="ve" enabled="true"/>
<service type="mapguide" enabled="true"/>
<service type="demo" enabled="true"/>
<errors>report</errors>
<locker type="disk">
<directory>/tmp</directory>
<timeout>300</timeout>
</locker>
</mapcache>

View file

@ -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