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

awx-operator restore from PVC is not working #1586

Closed
3 tasks done
romankuzmik opened this issue Oct 10, 2023 · 3 comments
Closed
3 tasks done

awx-operator restore from PVC is not working #1586

romankuzmik opened this issue Oct 10, 2023 · 3 comments

Comments

@romankuzmik
Copy link
Contributor

Please confirm the following

  • I agree to follow this project's code of conduct.
  • I have checked the current issues for duplicates.
  • I understand that the AWX Operator is open source software provided for free and that I might not receive a timely response.

Bug Summary

awx-operator/roles/restore/tasks/init.yml has wrong conditions on "Set variables from awxbackup object statuses if provided" block.

instead of:

  when:
    - backup_name != '' or backup_name is defined

it should be

  when:
    - backup_name is defined and backup_name != '' 

otherwise restore from PVC will fail with:

fatal: [localhost]: FAILED! => {"msg": "The conditional check 'backup_name != '' or backup_name is defined' failed. The error was: error while evaluating conditional (backup_name != '' or backup_name is defined): 'backup_name' is undefined. 'backup_name' is undefined

AWX Operator version

2.7.0

AWX version

23.3.0

Kubernetes platform

other (please specify in additional information)

Kubernetes/Platform version

v1.24.9

Modifications

no

Steps to reproduce

  1. Create restore from PVC manifest
apiVersion: awx.ansible.com/v1beta1
kind: AWXRestore
metadata:
  name: somebackup
  namespace: awx
spec:
  backup_dir: mybackupishere
  backup_pvc: mypvc
  backup_source: PVC
  deployment_name: awx
  image_pull_policy: IfNotPresent
  no_log: false
  set_self_labels: true
  1. Observe an error on operator pod

Expected results

AWX restore to complete successfully from PVC and folder within PVC specified

Actual results

AWX restore is in error loop

Additional information

No response

Operator Logs

No response

@kurokobo
Copy link
Contributor

kurokobo commented Oct 11, 2023

This is due to the version of Ansible in the Operator SDK.

In Operator 2.6.0 or eariler, Ansible 2.9.x is used in Operator SDK 1.28.x and the conditional works as expected.

In Operator 2.7.0, Operator SDK is bumped to 1.31.x that uses Ansible 2.15.x in #1550 and conditional is broken.

Operator 2.6.0

$ docker run --rm -it --entrypoint bash quay.io/ansible/awx-operator:2.6.0

bash-4.4$ ansible --version
ansible 2.9.27
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/usr/share/ansible/openshift']
  ansible python module location = /usr/local/lib/python3.8/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.8.13 (default, Jun 14 2022, 17:49:07) [GCC 8.5.0 20210514 (Red Hat 8.5.0-13)]

bash-4.4$ cat <<EOF > /tmp/site.yml
> ---
> - hosts: localhost
>   connection: local
>   gather_facts: false
>   tasks:
>     - block:
>       - ansible.builtin.debug:
>           msg: "Hello World!"
>       when:
>         - backup_name != '' or backup_name is defined
> EOF

bash-4.4$ ansible-playbook /tmp/site.yml

PLAY [localhost] ********************************************************************************************

TASK [ansible.builtin.debug] ********************************************************************************
skipping: [localhost]

PLAY RECAP **************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0   

Operator 2.7.0

$ docker run --rm -it --entrypoint bash quay.io/ansible/awx-operator:2.7.0

bash-4.4$ ansible --version
ansible [core 2.15.2]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/usr/share/ansible/openshift']
  ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
  ansible collection location = /opt/ansible/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True

bash-4.4$ cat <<EOF > /tmp/site.yml
> ---
> - hosts: localhost
>   connection: local
>   gather_facts: false
>   tasks:
>     - block:
>       - ansible.builtin.debug:
>           msg: "Hello World!"
>       when:
>         - backup_name != '' or backup_name is defined
> EOF

bash-4.4$ ansible-playbook /tmp/site.yml

PLAY [localhost] ********************************************************************************************

TASK [ansible.builtin.debug] ********************************************************************************
fatal: [localhost]: FAILED! => {"msg": "The conditional check 'backup_name != '' or backup_name is defined' failed. The error was: error while evaluating conditional (backup_name != '' or backup_name is defined): 'backup_name' is undefined. 'backup_name' is undefined\n\nThe error appears to be in '/tmp/site.yml': line 7, column 9, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n    - block:\n      - ansible.builtin.debug:\n        ^ here\n"}

PLAY RECAP **************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

@romankuzmik
Copy link
Contributor Author

condition was wrong from day one anyways, we first need to check that variable is defined and only then check is it is not empty. now, both order and logical operation is incorrect.

@rooftopcellist
Copy link
Member

This issue has been resolved by @romankuzmik 's PR here:

Thank you for the help @romankuzmik !

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

No branches or pull requests

3 participants