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

[chore] Update project_update playbook to be compliant with ansible-lint #13526

Merged

Conversation

TheRealHaoLiu
Copy link
Member

@TheRealHaoLiu TheRealHaoLiu commented Feb 7, 2023

SUMMARY

periodic therapeutic yak shaving...

TODO:

  • fix Commands should not change things if nothing needs doing.
    - name: Delete project directory before update
      ansible.builtin.command: "find -delete"  # volume mounted, cannot delete folder itself
      args:
        chdir: "{{ project_path }}"
      tags:
        - delete
  • fix File permissions unset or incorrect.
        - name: Ensure the project directory is present
          ansible.builtin.file:
            dest: "{{ project_path | quote }}"
            state: directory
  • fix File permissions unset or incorrect.
        - name: Ensure the project archive directory is present
         ansible.builtin.file:
           dest: "{{ project_path | quote }}/.archive"
           state: directory
  • fix File permissions unset or incorrect.
        - name: Get archive from url
          ansible.builtin.get_url:
            url: "{{ scm_url | quote }}"
            dest: "{{ project_path | quote }}/.archive/"
            url_username: "{{ scm_username | default(omit) }}"
            url_password: "{{ scm_password | default(omit) }}"
            force_basic_auth: true
ISSUE TYPE
  • Bug, Docs Fix or other nominal change
COMPONENT NAME
  • API
AWX VERSION
awx: 21.11.1.dev64+gcdbf20da64
ADDITIONAL INFORMATION

@TheRealHaoLiu TheRealHaoLiu changed the title Update project_update playbook to be compliant with ansible-lint [chore] Update project_update playbook to be compliant with ansible-lint Feb 7, 2023
@TheRealHaoLiu TheRealHaoLiu marked this pull request as ready for review February 7, 2023 16:32
@AlanCoding
Copy link
Member

I don't see ansible-lint in any of our checks?

- name: delete project directory before update
command: "find -delete" # volume mounted, cannot delete folder itself
- name: Delete project directory before update
ansible.builtin.command: "find -delete" # volume mounted, cannot delete folder itself
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this sufficiently version-compatible? A lot of people are surely using 2.9, which has collections, but not sure if this works.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we run project update in controlplane ee so we should be fine

in the latest awx-ee (stream9 based) we are running 2.14.2

args:
chdir: "{{ project_path }}"
tags:
- delete
changed_when: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't really correct. When the project folder contents are deleted, something is changed. If you're giving a value to changed_when, true would be a better shot at being correct. What if you gave changed=true and wrote another expression to skip the task where there are no contents inside the folder? That is the only way I can see making this correct.

Copy link
Member

@relrod relrod Feb 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why hardcode changed_when at all, as opposed to making it accurate? You can use find -delete -print, register the task output, and do something like changed_when: reg.stdout != "."

(that might not be exact, but that general idea)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i changed it to true is that good enough

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i changed it to true is that good enough

It's not accurate:

[rick@fedora asdf]$ find . -delete -print
.
[rick@fedora asdf]$ find . -delete -print
.

Why should changed be true the second time?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm worried about performance implications of any version of -print because it prints every file. If this is recorded in the event data (as stdout) then that is the exact thing we got ourselves in trouble with when we used the Ansible built-in module (I think file) for this purpose. Once you get to "large" repo sizes (realistically, any major project out there) then the sheer number of files becomes a problem, particularly when the .git folder is included. This kind of situation would make the page un-navigable in the UI and cause a mess of other problems.

You know, we don't even really need to make this determination in the playbook. Since the folder must be on the control node, we could determine in the task code whether there is anything to be deleted. You could even pass in a variable just for the somewhat ridiculous purpose of setting the changed status. This would be preferable to risking performance regressions.

Copy link
Member

@relrod relrod Feb 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is recorded in the event data (as stdout) then that is the exact thing we got ourselves in trouble with when we used the Ansible built-in module (I think file) for this purpose.

Okay, what about:

shell: find . -delete -print | head -2
register: reg
changed_when: reg.stdout_lines | length > 1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, that should be fine, because the bash commands will behave extremely efficiently in this case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheRealHaoLiu if you go this route, note you'll need shell and not command

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated as per @relrod's suggestion please re-review

Copy link
Member

@relrod relrod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me, but I'd like to see the blank lines between tasks preserved. I think they make enough of a difference when mentally/quickly parsing yaml.

register: results

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you preserve these blank lines between tasks? They make mentally parsing the YAML easier.

@AlanCoding
Copy link
Member

I wrote an integration test for the "changed" status. The test basically assures the following:

  • after you create a project with scm_delete_on_update as true, then it auto-updates and the delete task is changed=False, because there is nothing to delete
  • upon a second update, that same task gives changed=True

This requires having exactly 1 control node in the system. If this is working, then I'd like to merge this and merge the test.

@TheRealHaoLiu TheRealHaoLiu merged commit 283adc3 into ansible:devel Feb 23, 2023
@TheRealHaoLiu TheRealHaoLiu deleted the project_update_playbook_lint branch February 23, 2023 02:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants