@@ -10,12 +10,13 @@ Generic role for creating systemd services to manage docker containers.
1010 name : docker-systemd-service
1111 vars :
1212 name : myapp
13- image : myapp:latest
14- args : >
15- --link mysql
16- -v /data/uploads:/data/uploads
17- -p 3000:3000
18- env :
13+ container_image : myapp:latest
14+ container_links : [ 'mysql' ]
15+ container_volumes :
16+ - ' /data/uploads:/data/uploads'
17+ container_ports :
18+ - ' 3000:3000'
19+ container_env :
1920 MYSQL_ROOT_PASSWORD : " {{ mysql_root_pw }}"
2021` ` `
2122
@@ -27,20 +28,20 @@ This will create:
2728
2829# ## Role variables
2930
30- * `name` (**required**) - name of the service
31+ * `name` (**required**) - name of the container
3132
3233# ### Docker container specifics
3334
34- * `image ` (**required**) - Docker image the service uses
35- * `args ` - arbitrary list of arguments to the `docker run` command
36- * `cmd ` - optional command to the container run command (the part after the
35+ * `container_image ` (**required**) - Docker image the service uses
36+ * `container_args ` - arbitrary list of arguments to the `docker run` command
37+ * `container_cmd ` - optional command to the container run command (the part after the
3738 image name)
38- * `env ` - key/value pairs of ENV vars that need to be present
39- * `volumes ` (default: _[]_) - List of `-v` arguments
40- * `ports ` (default: _[]_) - List of `-p` arguments
41- * `link ` (default: _[]_) - List of `--link` arguments
42- * `labels ` (default: _[]_) - List of `-l` arguments
43- * `docker_pull ` (default: _yes_) - whether the docker image should be pulled
39+ * `container_env ` - key/value pairs of ENV vars that need to be present
40+ * `container_volumes ` (default: _[]_) - List of `-v` arguments
41+ * `container_ports ` (default: _[]_) - List of `-p` arguments
42+ * `container_link ` (default: _[]_) - List of `--link` arguments
43+ * `container_labels ` (default: _[]_) - List of `-l` arguments
44+ * `container_docker_pull ` (default: _yes_) - whether the docker image should be pulled
4445
4546# ### Systemd service specifics
4647
@@ -64,6 +65,9 @@ and run `ansible-galaxy install -r requirements.yml`.
6465
6566* When the unit or env file is changed, systemd gets reloaded but existing
6667 containers are NOT restarted.
68+ * Make sure to quote values for `container_ports`, `container_volumes` and so
69+ on, especially if they contain colons (`:`). Otherwise YAML will interpret
70+ them as hashes/maps and ansible will throw up.
6771
6872# # About orchestrating Docker containers using systemd.
6973
0 commit comments