playbookconfig: validate-config: update dict.keys()[0]

All '<dict>.keys()[0]' in yaml files should be updated to '<dict>.keys()|list|first'
after upgrading to Python3.
In Python2, the dict.keys(),dict.values(),dict.items() returns a list,
but in Python3, these methods return a dictionary view object.
The reported error message is:
"The task includes an option with an undefined variable.\
The error was: dict_keys object has no element 0"

Story: 2008454
Task: 41441

Signed-off-by: Haiqing Bai <haiqing.bai@windriver.com>
Change-Id: I7e41244759cffaa734e36a9d4d35478f21c96f83
(cherry picked from commit 816c028277)
This commit is contained in:
Haiqing Bai
2020-12-17 19:41:53 +08:00
committed by Charles Short
parent 95e3828e75
commit 6f473dd76c
3 changed files with 15 additions and 15 deletions

View File

@@ -14,7 +14,7 @@
# extract the name of the tar file
- name: Set application tar name
set_fact:
current_application_tar_name: "{{ application.keys()[0].split('/')[-1] }}"
current_application_tar_name: "{{ (application.keys()|list|first).split('/')[-1] }}"
# we assume the application tarball comes from a build and have the following format
# application-name-version.tgz where version is x.y-z
@@ -31,7 +31,7 @@
- block:
- name: Upload application
shell: "source /etc/platform/openrc;
system application-upload {{ application.keys()[0] }}"
system application-upload {{ application.keys()|list|first }}"
when: check_exist.stdout == ""
- name: Wait until application is in the uploaded state
@@ -45,10 +45,10 @@
- name: Apply overrides for application
shell: "source /etc/platform/openrc; system helm-override-update {{ current_application_name }}
{{ override_item['chart'] }} {{ override_item['namespace'] }} --values {{ override_item['values-path'] }}"
loop: "{{ application[application.keys()[0]]['overrides'] }}"
loop: "{{ application[application.keys()|list|first]['overrides'] }}"
loop_control:
loop_var: override_item
when: application[application.keys()[0]] and "overrides" in application[application.keys()[0]]
when: application[application.keys()|list|first] and "overrides" in application[application.keys()|list|first]
- name: Apply application
shell: "source /etc/platform/openrc; system application-apply {{ current_application_name }}"

View File

@@ -606,7 +606,7 @@
- name: Append applications to application list
set_fact:
all_applications: "{{ all_applications }} + [ '{{ item.keys()[0] }}' ]"
all_applications: "{{ all_applications }} + [ '{{ item.keys()|list|first }}' ]"
with_items: "{{ applications }}"
- name: Get the name of the nginx tarball

View File

@@ -24,7 +24,7 @@
# extract the name of the tar file
- name: Set application tar name
set_fact:
current_application_tar_name: "{{ application.keys()[0].split('/')[-1] }}"
current_application_tar_name: "{{ (application.keys()|list|first).split('/')[-1] }}"
- name: Fail if the application tarfile is not a valid type
fail:
@@ -33,17 +33,17 @@
- name: Check appication tarfile status
stat:
path: "{{ application.keys()[0] }}"
path: "{{ application.keys()|list|first }}"
register: tarball_stat
- name: Fail if the application tarfile doesn't exist
fail:
msg: "{{ application.keys()[0] }} doesn't exist"
msg: "{{ application.keys()|list|first }} doesn't exist"
when: not tarball_stat.stat.exists
- name: Fail if the provided application tarfile is a directory
fail:
msg: "{{ application.keys()[0] }} is a directory"
msg: "{{ application.keys()|list|first }} is a directory"
when: tarball_stat.stat.exists and tarball_stat.stat.isdir
- name: Fail if overrides config is incomplete
@@ -52,19 +52,19 @@
failed_when: '"chart" not in override_item or
"namespace" not in override_item or
"values-path" not in override_item'
loop: "{{ application[application.keys()[0]]['overrides'] }}"
loop: "{{ application[application.keys()|list|first]['overrides'] }}"
loop_control:
loop_var: override_item
when: (application[application.keys()[0]]) and
("overrides" in application[application.keys()[0]])
when: (application[application.keys()|list|first]) and
("overrides" in application[application.keys()|list|first])
- name: Fail if overrides file does not exist
stat:
path: "{{ override_item['values-path'] }}"
register: override_stat
failed_when: not override_stat.stat.exists
loop: "{{ application[application.keys()[0]]['overrides'] }}"
loop: "{{ application[application.keys()|list|first]['overrides'] }}"
loop_control:
loop_var: override_item
when: (application[application.keys()[0]]) and
("overrides" in application[application.keys()[0]])
when: (application[application.keys()|list|first]) and
("overrides" in application[application.keys()|list|first])