refactor(vars): simplify normalization and remove effective intermediates
This commit is contained in:
40
main.yml
40
main.yml
@@ -30,30 +30,6 @@
|
||||
system_input: "{{ system | default({}) }}"
|
||||
system_user_input: "{{ (system_input.user | default({})) if (system_input.user is mapping) else {} }}"
|
||||
system_root_input: "{{ (system_input.root | default({})) if (system_input.root is mapping) else {} }}"
|
||||
system_user_name_effective: >-
|
||||
{{
|
||||
(system_user_input.name | default('') | string)
|
||||
if (system_user_input.name | default('') | string | length) > 0
|
||||
else (system_user_name | default('') | string)
|
||||
}}
|
||||
system_user_public_key_effective: >-
|
||||
{{
|
||||
(system_user_input.public_key | default('') | string)
|
||||
if (system_user_input.public_key | default('') | string | length) > 0
|
||||
else (system_user_public_key | default('') | string)
|
||||
}}
|
||||
system_user_password_effective: >-
|
||||
{{
|
||||
(system_user_input.password | default('') | string)
|
||||
if (system_user_input.password | default('') | string | length) > 0
|
||||
else (system_user_password | default('') | string)
|
||||
}}
|
||||
system_root_password_effective: >-
|
||||
{{
|
||||
(system_root_input.password | default('') | string)
|
||||
if (system_root_input.password | default('') | string | length) > 0
|
||||
else (system_root_password | default('') | string)
|
||||
}}
|
||||
ansible.builtin.set_fact:
|
||||
system: >-
|
||||
{{
|
||||
@@ -61,12 +37,20 @@
|
||||
| combine(
|
||||
{
|
||||
'user': {
|
||||
'name': system_user_name_effective,
|
||||
'public_key': system_user_public_key_effective,
|
||||
'password': system_user_password_effective
|
||||
'name': (
|
||||
(system_user_input.name | default('') | string | length) > 0
|
||||
) | ternary(system_user_input.name | string, system_user_name | default('') | string),
|
||||
'public_key': (
|
||||
(system_user_input.public_key | default('') | string | length) > 0
|
||||
) | ternary(system_user_input.public_key | string, system_user_public_key | default('') | string),
|
||||
'password': (
|
||||
(system_user_input.password | default('') | string | length) > 0
|
||||
) | ternary(system_user_input.password | string, system_user_password | default('') | string)
|
||||
},
|
||||
'root': {
|
||||
'password': system_root_password_effective
|
||||
'password': (
|
||||
(system_root_input.password | default('') | string | length) > 0
|
||||
) | ternary(system_root_input.password | string, system_root_password | default('') | string)
|
||||
}
|
||||
},
|
||||
recursive=True
|
||||
|
||||
Reference in New Issue
Block a user