Skip to content

Commit ede861c

Browse files
authored
Merge pull request #432 from nextcloud/read-vars-for-occ-args
Allow occ based modules to consume ansible vars for their common arguments
2 parents 788edc9 + a565ae9 commit ede861c

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

plugins/action/run_occ.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,30 @@ class ActionModule(ActionBase):
1212
def run(self, tmp=None, task_vars=None):
1313
del tmp # tmp no longer has any effect
1414
new_module_args = copy.deepcopy(self._task.args)
15-
new_module_args["nextcloud_path"] = self._task.args.get(
16-
"nextcloud_path", os.getenv("NEXTCLOUD_PATH")
15+
16+
# missing occ common arguments fallback
17+
# argument value precedence: args > task_vars > environment
18+
nextcloud_path = (
19+
self._task.args.get("nextcloud_path")
20+
or task_vars.get("nextcloud_path")
21+
or os.getenv("NEXTCLOUD_PATH")
1722
)
18-
if not new_module_args["nextcloud_path"]:
23+
if nextcloud_path:
24+
new_module_args["nextcloud_path"] = nextcloud_path
25+
elif "nextcloud_path" in new_module_args:
1926
del new_module_args["nextcloud_path"]
2027

28+
# argument value precedence: args > task_vars > environment > default
29+
php_runtime = (
30+
self._task.args.get("php_runtime")
31+
or task_vars.get("nextcloud_php_runtime")
32+
or os.getenv("NEXTCLOUD_PHP_RUNTIME")
33+
)
34+
if php_runtime:
35+
new_module_args["php_runtime"] = php_runtime
36+
elif "php_runtime" in new_module_args:
37+
del new_module_args["php_runtime"]
38+
2139
return self._execute_module(
2240
module_name=self._task.action,
2341
module_args=new_module_args,

plugins/doc_fragments/occ_common_options.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class ModuleDocFragment(object):
3131
nextcloud_path:
3232
description:
3333
- Specify the nextcloud instance's location in the host.
34-
- Rollback to NEXTCLOUD_PATH environment variable on the ansible host
34+
- If not specified, the module will attempt to use the `nextcloud_path` var if it exists.
35+
- In last resort, read the `NEXTCLOUD_PATH` environment variable on the ansible host.
3536
type: str
3637
aliases:
3738
- path
@@ -43,6 +44,8 @@ class ModuleDocFragment(object):
4344
description:
4445
- Specify the php runtime used to run the occ tool.
4546
- Can be an absolute or relative path if the runtime is available in the remote host PATH.
47+
- If not specified, the module will attempt to use the `nextcloud_php_runtime` var if it exists,
48+
then the `NEXTCLOUD_PHP_RUNTIME` environment variable on the ansible host.
4649
type: str
4750
default: php
4851
aliases:

0 commit comments

Comments
 (0)