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

Update dnf.py #79679

Merged
merged 2 commits into from Feb 2, 2023
Merged

Update dnf.py #79679

merged 2 commits into from Feb 2, 2023

Conversation

bartlomiejkida
Copy link
Contributor

SUMMARY

Fix ansible-lint error: "Package installs should not use latest."

ISSUE TYPE
  • Docs Pull Request
COMPONENT NAME
  • Docs examples
ADDITIONAL INFORMATION

Example

[localhost:: ~ ]:$ cat test.yml 
- name: test playbook
  hosts: all
  tasks:
  - name: Upgrade all packages
    ansible.builtin.dnf:
      name: "*"
      state: latest
[localhost:: ~ ]:$ ansible-lint --version|grep using
ansible-lint 6.10.0 using ansible 2.14.1

[localhost:: ~ ]:$ ansible-lint test.yml 
WARNING  Overriding detected file kind 'yaml' with 'playbook' for given positional argument: test.yml
WARNING  Listing 2 violation(s) that are fatal
name[casing]: All names should start with an uppercase letter. (warning)
test.yml:1

package-latest: Package installs should not use latest.
test.yml:4 Task/Handler: Upgrade all packages

You can skip specific rules or tags by adding them to your configuration file:
# .config/ansible-lint.yml
warn_list:  # or 'skip_list' to silence them completely
  - package-latest  # Package installs should not use latest.

               Rule Violation Summary               
 count tag            profile  rule associated tags 
     1 name[casing]   moderate idiom (warning)      
     1 package-latest safety   idempotency          

Failed after basic profile, 1/5 star rating: 1 failure(s), 1 warning(s) on 1 files.
A new release of ansible-lint is available: 6.10.0 → 6.10.2

[localhost:: ~ ]:$ echo -e "      update_only: true" >> test.yml

[localhost:: ~ ]:$ ansible-lint test.yml 
WARNING  Overriding detected file kind 'yaml' with 'playbook' for given positional argument: test.yml
WARNING  Listing 1 violation(s) that are fatal
name[casing]: All names should start with an uppercase letter. (warning)
test.yml:1


              Rule Violation Summary              
 count tag          profile  rule associated tags 
     1 name[casing] moderate idiom (warning)      

Passed with basic profile, 1/5 star rating: 0 failure(s), 1 warning(s) on 1 files.
A new release of ansible-lint is available: 6.10.0 → 6.10.2

Fix ansible-lint error: "Package installs should not use latest."
@ansibot
Copy link
Contributor

ansibot commented Jan 6, 2023

Thanks for your Ansible docs contribution! We talk about Ansible documentation on matrix at #docs:ansible.im and on libera IRC at #ansible-docs if you ever want to join us and chat about the docs! We meet there on Tuesdays (see the Ansible calendar) and welcome additions to our weekly agenda items - scroll down to find the upcoming agenda and add a comment to put something new on that agenda.

click here for bot help

@ansibot ansibot added affects_2.15 docs This issue/PR relates to or includes documentation. docs_only All changes are to files within the docs/docsite/ directory module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. new_contributor This PR is the first contribution by a new community member. small_patch labels Jan 6, 2023
@@ -317,6 +317,7 @@
ansible.builtin.dnf:
name: "*"
state: latest
update_only: true
Copy link
Contributor

Choose a reason for hiding this comment

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

This would prevent any dependencies introduced in new versions of packages not being installed and ultimately failing the upgrade. I believe wanting to upgrade all packages regardless of whether they pull in new packages as their dependencies is a valid use case that is worth documenting.

@oraNod oraNod removed the needs_triage Needs a first human triage before being processed. label Jan 10, 2023
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Jan 18, 2023
@samccann
Copy link
Contributor

We have two examples here that use 'latest'. Both would cause an ansible-lint error. IMO one of the examples should be changed to show update_only in action. @mkrizek - would it be more appropriate to move this change to the other http example at

- name: Install the latest version of Apache
?
And change the name to "Update to latest version of Apache but do not install new dependencies" Or something like that to make clear what it is doing?

@mkrizek
Copy link
Contributor

mkrizek commented Jan 27, 2023

IMHO I would ignore this lint error. Using latest for installs is perfectly valid use case. Otherwise for cases where users do not wish to update the package (if available) on every playbook run (for example when reproducible environment is desired), state: present can be used instead.

Also, the lint error can be suppressed like so:

state: latest # noqa package-latest

Having said that I agree that the use of update_only should be documented.

I would add a new example that would better describe the intent of update_only, how about the following:

- name: Update the webserver, depending on which is installed on the system, do not install the other one
  ansible.builtin.dnf:
    name:
      - httpd
      - nginx
    state: latest
    update_only: yes

(the description in name could probably use better wording)

What do you think @samccann?

@samccann
Copy link
Contributor

@ssbarnea - do you have an opinion here since we're talking about ansible-lint errors ?

@ssbarnea
Copy link
Member

Thanks for pinging me. Yep, I think that it is a good idea to update the docs and use an example that is closer to what people are expected to use, and avoid use of examples that would not pass our linting.

@samccann
Copy link
Contributor

@ssbarnea That's where I think we have problems (using a real-world example w/o lint errors). If I understand correctly, @mkrizek is saying the existing example is already a real-world example, but will also throw ansible-lint errors using the default ansible-lint rules.

@s-hertel
Copy link
Contributor

s-hertel commented Jan 31, 2023

@samccann In case you haven't seen it already, here's ansible-lint's rationale https://github.com/ansible/ansible-lint/blob/dd29bc01d8643d7c016281158bde9eb4743d2346/src/ansiblelint/rules/package_latest.md. This PR wouldn't hide all examples that break the rule (at a glance, I see it in the yum and package examples too). Modules with more states than present/absent are a pet peeve so I can understand where the rule is coming from, but it's a valid use-case (and a common use case I'd guess) and there are no plans to deprecate it. I am in favor of adding a new example instead of replacing the existing one, as suggested by @mkrizek.

lib/ansible/modules/dnf.py Show resolved Hide resolved
lib/ansible/modules/dnf.py Outdated Show resolved Hide resolved
@ansibot ansibot removed small_patch stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Feb 2, 2023
@samccann samccann merged commit 0ab53ae into ansible:devel Feb 2, 2023
@samccann
Copy link
Contributor

samccann commented Feb 2, 2023

Thanks @wireboot for the PR and initiating the conversation around this fix! And welcome to the Ansible project.

@ansible ansible locked and limited conversation to collaborators Feb 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.15 docs_only All changes are to files within the docs/docsite/ directory docs This issue/PR relates to or includes documentation. module This issue/PR relates to a module. new_contributor This PR is the first contribution by a new community member.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants