Skip to content

Commit 368e29b

Browse files
committed
add ansible_to_faas arg converter
1 parent bfbac8f commit 368e29b

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

plugins/module_utils/faas.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,16 @@ def global_args_to_cmd(args: dict = {}) -> list[str]:
108108
raise FileNotFoundError(f'Function config file does not exist or is invalid: {config_file}')
109109

110110
return command
111+
112+
113+
def ansible_to_faas(args: dict) -> dict[str, list[str], bool]:
114+
"""converts ansible types and syntax to faas types and formatting for arguments only"""
115+
# in this function args dict is mutable pseudo-reference and also returned
116+
# iterate through ansible module argument
117+
for arg, arg_value in args.items():
118+
match arg:
119+
# transform dict[str, str] to single "key=value key2=value2" string
120+
case 'annotation' | 'label':
121+
args[arg] = ' '.join([f'{key}={value}' for key, value in arg_value.items()])
122+
123+
return args

plugins/module_utils/packer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def ansible_to_packer(args: dict) -> dict[str, (str, list[str])]:
9393
# list[str] to comma-delimited string
9494
case 'excepts' | 'only':
9595
args[arg] = ','.join(arg_value)
96-
# list[dict[str, str]] to "key=value" string with args for n>1 values
96+
# dict[str, str] to "key=value" string with args for n>1 values
9797
case 'var':
9898
# assign converted value to var key
9999
args['var'] = universal.vars_converter(arg_value)

plugins/module_utils/terraform.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def ansible_to_terraform(args: dict) -> dict[str, (str, list[str])]:
201201
# below for single resource also requires flattening
202202
# address should not require shell string cast since executed as ansible command and not in shell interpreter
203203
args[arg] = list(itertools.chain.from_iterable([[address, id] for address, id in arg_value.items()]))
204-
# list[dict[str, str]] to "key=value" string with args for n>1 values
204+
# dict[str, str] to "key=value" string with args for n>1 values
205205
case 'var':
206206
# assign converted value to var key
207207
args['var'] = universal.vars_converter(arg_value)

0 commit comments

Comments
 (0)