ansible-collections / ansible.posix

Ansible Collection for Posix
Other
159 stars 153 forks source link

If a comment is appended to a fstab entry state present creates a double-entry . #595

Open vbotka opened 1 week ago

vbotka commented 1 week ago
SUMMARY

Given the /tmp/fstab for testing

shell> cat /tmp/fstab 
/dev/sda /mnt3 ntfs3 defaults 0 0 # mount sda to /mnt3

the module ansible.posix.mount

    - ansible.posix.mount:
        fstab: /tmp/fstab
        src: /dev/sda
        path: /mnt3
        fstype: ntfs3
        state: present

creates a double-entry

shell> cat /tmp/fstab 
/dev/sda /mnt3 ntfs3 defaults 0 0 # mount sda to /mnt3
/dev/sda /mnt3 ntfs3 defaults 0 0
ISSUE TYPE
COMPONENT NAME

ansible.posix.mount

ANSIBLE VERSION
shell> ansible --version
ansible [core 2.18.0]
  config file = /export/scratch/sandbox/tmp1/test-101/ansible.cfg
  configured module search path = ['/home/vlado/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/vlado/env/lib/python3.12/site-packages/ansible
  ansible collection location = /home/vlado/env/lib/python3.12/site-packages/ansible_collections
  executable location = /home/vlado/env/bin/ansible
  python version = 3.12.3 (main, Sep 11 2024, 14:17:37) [GCC 13.2.0] (/home/vlado/env/bin/python3)
  jinja version = 3.1.4
  libyaml = True
COLLECTION VERSION
shell> ansible-galaxy collection list ansible.posix

# /home/vlado/env/lib/python3.12/site-packages/ansible_collections
Collection    Version
------------- -------
ansible.posix 1.6.2
CONFIGURATION
ANSIBLE_PIPELINING(/export/scratch/sandbox/tmp1/test-101/ansible.cfg) = True
CONFIG_FILE() = /export/scratch/sandbox/tmp1/test-101/ansible.cfg
DEFAULT_GATHERING(/export/scratch/sandbox/tmp1/test-101/ansible.cfg) = explicit
DEFAULT_HOST_LIST(/export/scratch/sandbox/tmp1/test-101/ansible.cfg) = ['/scratch/sandbox/tmp1/test-101/hosts']
DEFAULT_ROLES_PATH(/export/scratch/sandbox/tmp1/test-101/ansible.cfg) = ['/scratch/sandbox/tmp1/test-101/roles']
DEFAULT_STDOUT_CALLBACK(/export/scratch/sandbox/tmp1/test-101/ansible.cfg) = yaml
EDITOR(env: EDITOR) = emacs
PAGER(env: PAGER) = /usr/bin/most -s

GALAXY_SERVERS:
OS / ENVIRONMENT
shell> cat /etc/os-release 
PRETTY_NAME="Ubuntu 24.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.1 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo
STEPS TO REPRODUCE

Create /tmp/fstab for testing

shell> cat /tmp/fstab 
/dev/sda /mnt3 ntfs3 defaults 0 0 # mount sda to /mnt3

Run the play

shell> cat pb.yml 
- hosts: localhost

  tasks:

    - ansible.posix.mount:
        fstab: /tmp/fstab
        src: /dev/sda
        path: /mnt3
        fstype: ntfs3
        state: present
EXPECTED RESULTS

The task should be idempotent. This means, nothing will be changed because the entry in fstab is present

shell> cat /tmp/fstab 
/dev/sda /mnt3 ntfs3 defaults 0 0 # mount sda to /mnt3
ACTUAL RESULTS

A double entry is created

shell> cat /tmp/fstab 
/dev/sda /mnt3 ntfs3 defaults 0 0 # mount sda to /mnt3
/dev/sda /mnt3 ntfs3 defaults 0 0
saito-hideki commented 17 hours ago

@vbotka thanks for the PR!

In accordance with the community guidelines, a changelog fragment file is required for all PR. So, could you add a changelog fragment file to this PR? You can see more details here: Making your PR merge-worthy You can write a short description for this PR in the bugfixes section.

For example: https://github.com/ansible-collections/ansible.posix/blob/main/changelogs/fragments/570_nfs4_acl.yml

vbotka commented 16 hours ago

changelog fragment file is required

Changelog fragment added to #597. Thank you!