Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sap_swpm: incorrect label in loop in swpm.yml #681

Closed
rnozaki opened this issue Mar 9, 2024 · 9 comments
Closed

sap_swpm: incorrect label in loop in swpm.yml #681

rnozaki opened this issue Mar 9, 2024 · 9 comments
Assignees

Comments

@rnozaki
Copy link
Contributor

rnozaki commented Mar 9, 2024

  1. In the file swpm.yml, under the role sap_swpm one of the tasks is pointing to an incorrect name for a label in a loop_control.
- name: SAP SWPM - Display status from sapcontrol file/s
  ansible.builtin.debug:
    msg: "{{ ['GetInstanceProperties'] + file_output.stdout_lines }}"
  loop: "{{ swpm_sapcontrol_file_contents.results }}"
  loop_control:
    loop_var: file_output
    label: "{{ file_output.item }}"       # << This should be line_item, as this was added recently to a loop in a previous task
  1. After I used the dev branch (from PR $665), I got the following error:
###
TASK [community.sap_install.sap_swpm : SAP SWPM - Display status from sapcontrol file/s] ***15:12:00
failed: [xxxxxx] (item=None) => {
"msg": "Failed to template loop_control.label: 'dict object' has no attribute 'item'"
}
fatal: [xxxxxx]: FAILED! => {"msg": "One or more items failed"}
  1. I noticed that 2 tasks above there was a recent change adding the loop_var under loop_control.

  2. So I updated the code:
    a. From: label: "{{ file_output.item }}"
    b. To: label: "{{ file_output.line_item }}"

  3. With this update, the playbook was re-executed without error.

@marcelmamula
Copy link
Contributor

Did you check previous step in execution log that it registered that variable? It is possible it did not find any files, therefore item was not defined.

I have been running it in current state and I never had this issue with .item.

- name: SAP SWPM - Find sapcontrol log file/s
  ansible.builtin.find:
    paths: "{{ swpm_last_install_path.stdout }}"
    recurse: false
    file_type: file
    patterns: '.*sapcontrol.*log'
    use_regex: true
  register: swpm_output_sapcontrol_files

@berndfinger
Copy link
Member

@rnozaki I had the same error when testing an S/4HANA Foundation 2022 installation last week but I could not finish my investigation. Trying to reproduce it again now and also testing the solution you proposed.

@berndfinger berndfinger self-assigned this Mar 11, 2024
@rnozaki
Copy link
Contributor Author

rnozaki commented Mar 11, 2024

Did you check previous step in execution log that it registered that variable? It is possible it did not find any files, therefore item was not defined.

I have been running it in current state and I never had this issue with .item.

- name: SAP SWPM - Find sapcontrol log file/s
  ansible.builtin.find:
    paths: "{{ swpm_last_install_path.stdout }}"
    recurse: false
    file_type: file
    patterns: '.*sapcontrol.*log'
    use_regex: true
  register: swpm_output_sapcontrol_files

As I mentioned, I tested the new code with the exact same conditions it was working before.
And when I added the new label, it found the element.
So in my case, just fixing the label solved the problem.

Have you executed this code in your environment?

@marcelmamula
Copy link
Contributor

Did you check previous step in execution log that it registered that variable? It is possible it did not find any files, therefore item was not defined.
I have been running it in current state and I never had this issue with .item.

- name: SAP SWPM - Find sapcontrol log file/s
  ansible.builtin.find:
    paths: "{{ swpm_last_install_path.stdout }}"
    recurse: false
    file_type: file
    patterns: '.*sapcontrol.*log'
    use_regex: true
  register: swpm_output_sapcontrol_files

As I mentioned, I tested the new code with the exact same conditions it was working before. And when I added the new label, it found the element. So in my case, just fixing the label solved the problem.

Have you executed this code in your environment?

That is why I was mentioning previous step. It would be good to know what was actual content of your "{{ swpm_output_sapcontrol_files }}" variable and if it contains array with items.

I have run this role 20+ times over last 2 weeks (ASCS/ERS, S4H, NW) and it never failed with this error, even if SWPM was successful or failed.

@rnozaki
Copy link
Contributor Author

rnozaki commented Mar 11, 2024

Did you check previous step in execution log that it registered that variable? It is possible it did not find any files, therefore item was not defined.
I have been running it in current state and I never had this issue with .item.

- name: SAP SWPM - Find sapcontrol log file/s
  ansible.builtin.find:
    paths: "{{ swpm_last_install_path.stdout }}"
    recurse: false
    file_type: file
    patterns: '.*sapcontrol.*log'
    use_regex: true
  register: swpm_output_sapcontrol_files

As I mentioned, I tested the new code with the exact same conditions it was working before. And when I added the new label, it found the element. So in my case, just fixing the label solved the problem.
Have you executed this code in your environment?

That is why I was mentioning previous step. It would be good to know what was actual content of your "{{ swpm_output_sapcontrol_files }}" variable and if it contains array with items.

I have run this role 20+ times over last 2 weeks (ASCS/ERS, S4H, NW) and it never failed with this error, even if SWPM was successful or failed.

Have you run it in the last 3 days? Because this is when the PR 665 was merged.

@marcelmamula
Copy link
Contributor

Sorry @rnozaki , it seems @berndfinger moved his PR and it changed items as you said. I have not tested it with his PR. You can disregard my comments.

@berndfinger
Copy link
Member

@rnozaki @marcelmamula In #665, I overlooked the fact that the loop variable from the task SAP SWPM - Get sapcontrol file/s is re-used for the label in the task SAP SWPM - Display status from sapcontrol file/s.
Thanks for solving the problem @rnozaki!

@berndfinger
Copy link
Member

Solved in #682.

@berndfinger
Copy link
Member

FYI - Test playbook for those who want to reproduce the problem:

- name: junk
  hosts: localhost
  vars:
    dummy:
      - 'test1'
      - 'test2'

  gather_facts: no

  tasks:

    - name: Display the list
      ansible.builtin.debug:
        msg: "{{ dummy }}"
 
    - name: Run command and register output with new loop_var
      ansible.builtin.command: "echo {{ line_item }}" 
      register: output
      loop: "{{ dummy }}"
      loop_control:
        loop_var: line_item

    - name: Display output with correct loop label
      ansible.builtin.debug:
        msg: "{{ command_output.stdout_lines }}"
      loop: "{{ output.results }}"
      loop_control:
        loop_var: command_output
        label: "{{ command_output.line_item }}"

    - name: Display output with wrong loop label
      ansible.builtin.debug:
        msg: "{{ command_output.stdout_lines }}"
      loop: "{{ output.results }}"
      loop_control:
        loop_var: command_output
        label: "{{ command_output.item }}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants