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

Module interfaces_file ignore option line not starting with a space #6120

Closed
1 task done
olivier-monaco opened this issue Mar 1, 2023 · 3 comments · Fixed by #6131
Closed
1 task done

Module interfaces_file ignore option line not starting with a space #6120

olivier-monaco opened this issue Mar 1, 2023 · 3 comments · Fixed by #6131
Labels
bug This issue/PR relates to a bug has_pr module module plugins plugin (any type) system

Comments

@olivier-monaco
Copy link

olivier-monaco commented Mar 1, 2023

Summary

When the module interfaces_file look for options in the interfaces file, it use the following regexp (https://github.com/ansible-collections/community.general/blob/main/plugins/modules/interfaces_file.py#L168):

    patt = re.compile(r'^\s+(?P<option>\S+)\s+(?P<value>\S?.*\S)\s*$')

It required each option line to start with at least one space character (^\s+). The module ignore option lines not starting with space. Modifying this option results in duplicate lines.

To fix this issue, replace + by *:

    patt = re.compile(r'^\s*(?P<option>\S+)\s+(?P<value>\S?.*\S)\s*$')

Issue Type

Bug Report

Component Name

interfaces_file

Ansible Version

ansible [core 2.14.3]
  config file = /home/olivier/xxxxxxx/ansible.cfg
  configured module search path = ['/home/olivier/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.11/dist-packages/ansible
  ansible collection location = /home/olivier/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.11.1 (main, Dec 31 2022, 10:23:59) [GCC 12.2.0] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True

Community.general Version

# /usr/local/lib/python3.11/dist-packages/ansible_collections
Collection        Version
----------------- -------
community.general 6.4.0  

Configuration

No response

OS / Environment

No response

Steps to Reproduce

The task:

- name: Set MTU for eth1
  community.general.interfaces_file:
    iface: "eth1"
    option: mtu
    value: "9000"
    state: present

My interfaces file before:

iface lo inet loopback
auto lo

auto ens192
iface ens192 inet static                                                                                                                                   
address 10.0.0.1
netmask 255.255.255.0
mtu 1500

Expected Results

iface lo inet loopback
auto lo

auto ens192
iface ens192 inet static                                                                                                                                   
address 10.0.0.1
netmask 255.255.255.0
mtu 9000

Actual Results

iface lo inet loopback
auto lo

auto ens192
iface ens192 inet static                                                                                                                                   
address 10.0.0.1
netmask 255.255.255.0
mtu 1500
mtu 9000

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibullbot
Copy link
Collaborator

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added bug This issue/PR relates to a bug module module plugins plugin (any type) system labels Mar 1, 2023
@hryamzik
Copy link
Contributor

hryamzik commented Mar 2, 2023

Oh my, this is exactly why I implemented initial module rewriting C code to python line by line.

Now I think we should revert changes from @russoz in #3328 as they don't add any value but result in issues like this. That's the third one!

I have actually raised my concerns in the review.

hryamzik added a commit to hryamzik/community.general that referenced this issue Mar 2, 2023
felixfontein added a commit that referenced this issue Mar 9, 2023
* interfaces_file: added test case for #6120

* interfaces_file: reverted code to #fafabed

* interfaces_file: added changelog fragment

* interfaces_file: added missing licenses

* interfaces_file: improved test coverage

* interfaces_file: fixed retrieving option values

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update tests/unit/plugins/modules/interfaces_file/test_interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update tests/unit/plugins/modules/interfaces_file/test_interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* interfaces_file: spacing fix

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
patchback bot pushed a commit that referenced this issue Mar 9, 2023
* interfaces_file: added test case for #6120

* interfaces_file: reverted code to #fafabed

* interfaces_file: added changelog fragment

* interfaces_file: added missing licenses

* interfaces_file: improved test coverage

* interfaces_file: fixed retrieving option values

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update tests/unit/plugins/modules/interfaces_file/test_interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update tests/unit/plugins/modules/interfaces_file/test_interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* interfaces_file: spacing fix

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit abcba9d)
felixfontein pushed a commit to felixfontein/community.general that referenced this issue Mar 9, 2023
* interfaces_file: added test case for ansible-collections#6120

* interfaces_file: reverted code to #fafabed

* interfaces_file: added changelog fragment

* interfaces_file: added missing licenses

* interfaces_file: improved test coverage

* interfaces_file: fixed retrieving option values

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update tests/unit/plugins/modules/interfaces_file/test_interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update tests/unit/plugins/modules/interfaces_file/test_interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* interfaces_file: spacing fix

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit abcba9d)
felixfontein pushed a commit that referenced this issue Mar 9, 2023
)

Interfaces file spaces fix (#6131)

* interfaces_file: added test case for #6120

* interfaces_file: reverted code to #fafabed

* interfaces_file: added changelog fragment

* interfaces_file: added missing licenses

* interfaces_file: improved test coverage

* interfaces_file: fixed retrieving option values

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update tests/unit/plugins/modules/interfaces_file/test_interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update tests/unit/plugins/modules/interfaces_file/test_interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* interfaces_file: spacing fix

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit abcba9d)

Co-authored-by: Roman Belyakovsky <roman.beliakovskii@smartly.io>
felixfontein added a commit that referenced this issue Mar 14, 2023
Interfaces file spaces fix (#6131)

* interfaces_file: added test case for #6120

* interfaces_file: reverted code to #fafabed

* interfaces_file: added changelog fragment

* interfaces_file: added missing licenses

* interfaces_file: improved test coverage

* interfaces_file: fixed retrieving option values

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update tests/unit/plugins/modules/interfaces_file/test_interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update tests/unit/plugins/modules/interfaces_file/test_interfaces_file.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* interfaces_file: spacing fix

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit abcba9d)

Co-authored-by: Roman Belyakovsky <roman.beliakovskii@smartly.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug has_pr module module plugins plugin (any type) system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants