Skip to content

Commit 0e72752

Browse files
committed
safely returns an empty dict if the OS key doesn’t exist
1 parent aa35dbc commit 0e72752

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

ansible/roles/dnf_repos/tasks/set_repos.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
label: "{{ repo_name }}[{{ repo_os }}]: {{ repo_values }}"
1515
when:
1616
- repo_name != 'epel'
17-
- repo_os in item.value
17+
- repo_values | length > 0
1818
vars:
1919
repo_os: "{{ ansible_distribution_version if ansible_distribution_version in item.value else ansible_distribution_major_version }}"
20-
repo_values: "{{ item.value[repo_os] | default({}) }}"
20+
repo_values: "{{ item.value.get(repo_os, {}) }}"
2121
repo_name: "{{ repo_values.repo_name | default(item.key) }}"
2222
repo_content_url: "{{ repo_values.pulp_content_url | default(dnf_repos_pulp_content_url) }}"
2323

@@ -40,9 +40,9 @@
4040
label: "{{ repo_name }}[{{ repo_os }}]: {{ repo_values }}"
4141
when:
4242
- repo_name == 'epel'
43-
- repo_os in item.value
43+
- repo_values | length > 0
4444
vars:
4545
repo_os: "{{ ansible_distribution_version if ansible_distribution_version in item.value else ansible_distribution_major_version }}"
46-
repo_values: "{{ item.value[repo_os] | default({}) }}"
46+
repo_values: "{{ item.value.get(repo_os, {}) }}"
4747
repo_name: "{{ repo_values.repo_name | default(item.key) }}"
4848
repo_content_url: "{{ repo_values.pulp_content_url | default(dnf_repos_pulp_content_url) }}"

0 commit comments

Comments
 (0)