Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flags option for dokku_service_link #80

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
19 changes: 17 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 All @@ -169,6 +183,7 @@ def main():
"app": {"required": True, "type": "str"},
"name": {"required": True, "type": "str"},
"service": {"required": True, "type": "str"},
"flags": {"required": False, "type": "dict"},
"state": {
"required": False,
"default": "present",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ansible-lint
black
docker==4.2.0
flake8
molecule==3.0.2
molecule==3.0.3
pyyaml
testinfra==5.0.0
yamllint