Skip to content

Commit

Permalink
Add flags option for dokku_service_link
Browse files Browse the repository at this point in the history
  • Loading branch information
nerg4l committed Sep 27, 2020
1 parent 3797fc3 commit 6b0be7d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ Links and unlinks a given service to an application
|Parameter|Choices/Defaults|Comments|
|---------|----------------|--------|
|app<br /><sup>*required*</sup>||The name of the app|
|flags|*Default:* {}|The flags for the service|
|name<br /><sup>*required*</sup>||The name of the service|
|service<br /><sup>*required*</sup>||The type of service to link|
|state|*Choices:* <ul><li>**present** (default)</li><li>absent</li></ul>|The state of the service link|
Expand All @@ -604,6 +605,8 @@ Links and unlinks a given service to an application
app: hello-world
name: default
service: redis
flags:
alias: BLUE_DATABASE
- name: redis:unlink default hello-world
dokku_service_link:
Expand Down
18 changes: 16 additions & 2 deletions library/dokku_service_link.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# from ansible.module_utils.basic import *
import pipes

from ansible.module_utils.basic import AnsibleModule
import subprocess

Expand All @@ -27,6 +29,12 @@
required: True
default: null
aliases: []
flags:
description:
- The flags for the service
required: False
default: {}
aliases: []
state:
description:
- The state of the service link
Expand All @@ -44,6 +52,8 @@
app: hello-world
name: default
service: redis
flags:
alias: BLUE_DATABASE
- name: redis:unlink default hello-world
dokku_service_link:
Expand Down Expand Up @@ -150,8 +160,12 @@ def dokku_service_link_present(data):
is_error = False
return (is_error, has_changed, meta)

command = "dokku --quiet {0}:link {1} {2}".format(
data["service"], data["name"], data["app"]
values = []
for key, value in data["flags"].items():
values.append('--{0}={1}'.format(key, pipes.quote(value)))

command = "dokku --quiet {0}:link {1} {2} {3}".format(
data["service"], data["name"], data["app"], " ".join(values)
)
try:
subprocess.check_call(command, shell=True)
Expand Down

0 comments on commit 6b0be7d

Please sign in to comment.