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

check if there attributes to set #78707

Merged
merged 1 commit into from
Dec 6, 2023
Merged

check if there attributes to set #78707

merged 1 commit into from
Dec 6, 2023

Conversation

pc-explore
Copy link
Contributor

Add fix for issue 76727: check if there attributes to set before attempting to set them

SUMMARY

When there are no attributes to be set, the command 'chattr' will fail with 'Operation not supported' when setting the attributes of the backupfile.
Fixes #76727

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py

ADDITIONAL INFORMATION
Error before change:
_Error while setting attributes: ./test-76727.txt.3395762.2022-09-04@19:05:40~: Operation not supported_

@ansibot ansibot added affects_2.14 bug This issue/PR relates to a bug. core_review In order to be merged, this PR must follow the core review workflow. needs_triage Needs a first human triage before being processed. new_contributor This PR is the first contribution by a new community member. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Sep 4, 2022
@mkrizek mkrizek added P3 Priority 3 - Approved, No Time Limitation and removed needs_triage Needs a first human triage before being processed. labels Sep 6, 2022
@sivel sivel added the needs_verified This issue needs to be verified/reproduced by maintainer label Sep 12, 2022
@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 Sep 12, 2022
@lancedikson
Copy link

Just encountered a similar issue and the PR seems potentially could work in my case. I'm trying to edit the /etc/resolv.conf which is a symlink and it doesn't get through

    - name: Set ndots to 5 in resolv.conf
      lineinfile:
        path: /etc/resolv.conf
        regexp: '^options.*'
        line: '{{ (item|regex_replace("^options", "")|trim + " ndots:5") if item is search("ndots:") else "options ndots:5" }}'
        backup: no
      loop: "{{ lookup('file', '/etc/resolv.conf').splitlines() }}"
      tags:
        - ndots

And get the exception:

The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_lineinfile_payload_vvsy6qs8/ansible_lineinfile_payload.zip/ansible/module_utils/basic.py", line 1003, in set_attributes_if_different
    raise Exception("Error while setting attributes: %s" % (out + err))
Exception: Error while setting attributes: /etc/resolv.conf.2644211.2023-04-16@08:57:43~: Operation not supported

failed: [server-0] (item=#) => {
    "ansible_loop_var": "item",
    "changed": false,
    "details": "Error while setting attributes: /etc/resolv.conf.2644211.2023-04-16@08:57:43~: Operation not supported\n",
    "gid": 103,
    "group": "systemd-resolve",
    "invocation": {
        "module_args": {
            "attributes": null,
            "backrefs": false,
            "backup": true,
            "create": false,
            "firstmatch": false,
            "group": null,
            "insertafter": null,
            "insertbefore": null,
            "line": "options ndots:5",
            "mode": null,
            "owner": null,
            "path": "/etc/resolv.conf",
            "regexp": "^options.*",
            "search_string": null,
            "selevel": null,
            "serole": null,
            "setype": null,
            "seuser": null,
            "state": "present",
            "unsafe_writes": false,
            "validate": null
        }
    },
    "item": "#",
    "mode": "0644",
    "msg": "chattr failed",
    "owner": "systemd-resolve",
    "path": "/etc/resolv.conf.2644211.2023-04-16@08:57:43~",
    "size": 920,
    "state": "file",
    "uid": 102
}

Copy link

@lancedikson lancedikson left a comment

Choose a reason for hiding this comment

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

Just tried the fix on ansible [core 2.14.3] — seems working for me! 👍

@webknjaz

This comment was marked as resolved.

@azure-pipelines

This comment was marked as resolved.

@ansibot ansibot added the needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. label Oct 31, 2023
@webknjaz
Copy link
Member

The branch is too old for the CI to pick it up. This needs a rebase.

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. 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 Oct 31, 2023
@webknjaz webknjaz added the ci_verified Changes made in this PR are causing tests to fail. label Oct 31, 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 Nov 14, 2023
@Akasurde Akasurde changed the title Add fix for issue 76727: check if there attributes to set check if there attributes to set Nov 22, 2023
@ansibot ansibot removed ci_verified Changes made in this PR are causing tests to fail. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Nov 22, 2023
@Akasurde
Copy link
Member

Akasurde commented Dec 5, 2023

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Dec 5, 2023
@Akasurde Akasurde merged commit 9b002d2 into ansible:devel Dec 6, 2023
62 checks passed
@sivel sivel removed the needs_verified This issue needs to be verified/reproduced by maintainer label Dec 7, 2023
@ansible ansible locked and limited conversation to collaborators Jan 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.14 bug This issue/PR relates to a bug. core_review In order to be merged, this PR must follow the core review workflow. has_issue new_contributor This PR is the first contribution by a new community member. P3 Priority 3 - Approved, No Time Limitation support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
7 participants