commit e0a7bdb45d32efd12b9160c7612e5d355a8d8838 Author: Egon Rijpkema Date: Tue Apr 18 13:17:32 2017 +0200 initial commit diff --git a/files/mysql.service b/files/mysql.service new file mode 100644 index 0000000..c82c263 --- /dev/null +++ b/files/mysql.service @@ -0,0 +1,16 @@ +[Unit] +Description=Mariadb Container +After=docker.service +Requires=docker.service + +[Service] +TimeoutStartSec=0 +Restart=always +ExecStartPre=-/usr/bin/docker stop %n +ExecStartPre=-/usr/bin/docker rm %n +ExecStartPre=/usr/bin/docker pull mariadb:10.1.22 +ExecStart=/usr/bin/docker run -p 3306:3306 --name %n -v /srv/lib/mysql:/var/lib/mysql \ + -e MYSQL_ROOT_PASSWORD=geheim mariadb:10.1.22 + +[Install] +WantedBy=multi-user.target diff --git a/mariadb.yml b/mariadb.yml new file mode 100644 index 0000000..523155b --- /dev/null +++ b/mariadb.yml @@ -0,0 +1,23 @@ +# Install a docker based mariadb. +--- +- name: Install a mariadb server with databases in a persistent volume + hosts: all # Should be specified of course + become: True + tasks: + - name: install docker packages + apt: pkg={{ item }} state=latest update_cache=yes + with_items: + - docker-engine + - name: install service file. + template: + src: files/mysql.service + dest: /etc/systemd/system/mysql.service + mode: 644 + owner: root + group: root + - name: install service file + command: systemctl daemon-reload + - name: make sure service is started + systemd: + name: mariadb.service + state: started