Closed jplitza closed 4 years ago
Files identified in the description:
If these files are inaccurate, please update the component name
section of the description or use the !component
bot command.
cc @MorrisA @bcoca @d-little @flynn1973 @gforster @hryamzik @kairoaraujo @marvin-sinister @mator @molekuul @obourdon @ramooncamacho @wtcross click here for bot help
I just noticed that interfaces_file expects "post-down" to actually be "down", so my example is treated as a value that should be replaced instead of added. If I use option: down
, it works as intended.
However, the bug still exists in all other options. Will change the example.
Should be easy to fix (if the problem is in the line you say), by replacing that line with
old_value_position = re.search(r"\s+".join([re.escape(part) for part in old_value.split()]), old_line[prefix_start + optionLen:])
(with appropriate line breaks to avoid linting errors :) )
@jplitza do you want to create a PR?
@felixfontein I have had terrible experiences with PRs for Ansible, having to re-create them several times in different projects because of restructuring, having to rebase them due to lack of response, and having to write changelogs without any guidance as to what to write where.
So with all due respect: No, I do not want to create a PR.
i can't reproduce it on debian10 Debian GNU/Linux 10 (buster)
with the development/git version of ansible:
$ ansible --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out
features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible 2.11.0.dev0
config file = /home/mator/ansible.dev/ansible.cfg
configured module search path = ['/home/mator/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mator/ansible.dev/ansible/lib/ansible
ansible collection location = /home/mator/ansible.dev/collections
executable location = /home/mator/ansible.dev/ansible/bin/ansible
python version = 3.8.5 (default, Jul 27 2020, 08:42:51) [GCC 10.1.0]
just before playbook run:
root@debian10:/etc/network# tail -n 2 interfaces
iface dummy0 inet manual
running:
$ cat playbooks/debian-interfaces.yml
- hosts: debian10
gather_facts: no
tasks:
- interfaces_file:
iface: dummy0
option: description
value: 'Funny || name'
- interfaces_file:
iface: dummy0
option: down
value: 'Another || funny || name'
$ ansible-playbook -b playbooks/debian-interfaces.yml
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out
features under development. This is a rapidly changing source of code and can become unstable at any point.
PLAY [debian10] ****************************************************************************************************************************************************
TASK [interfaces_file] *********************************************************************************************************************************************
changed: [debian10]
TASK [interfaces_file] *********************************************************************************************************************************************
changed: [debian10]
PLAY RECAP *********************************************************************************************************************************************************
debian10 : ok=2 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
checking:
root@debian10:/etc/network# tail -n 3 interfaces
iface dummy0 inet manual
description Funny || name
down Another || funny || name
@mator Sorry, I messed up the example. The second task should of course also modify "description" and not "down". Fixed.
@jplitza thanks, was able to reproduce...
@felixfontein , yep, that line
old_value_position = re.search(r"\s+".join([re.escape(part) for part in old_value.split()]), old_line[prefix_start + optionLen:])
fixes it for me... want me to submit PR ?
@felixfontein I have had terrible experiences with PRs for Ansible, having to re-create them several times in different projects because of restructuring, having to rebase them due to lack of response,
I guess you are refering to ansible/ansible#68362, #88, #89, ansible-collections/community.network#7 and ansible-collections/community.network#6. You unfortunately hit two different problems:
I'm sorry that your experience was so terrible, especially for the edgeos PRs. I would have liked to review the PR's content, but I have no knowledge about edgeos at all, so I had no idea (and still not really have one) whether your PR is correct, needs changes, or is even plain wrong.
and having to write changelogs without any guidance as to what to write where.
You did ask and got suggestions and a link to an example.
So with all due respect: No, I do not want to create a PR.
That's too bad, because in this case, your change is a lot easier to judge without needing domain knowledge (i.e. I would dare to merge it), and there are active maintainers (@mator :+1:). But if you don't want to, that's also ok. @mator if you want, feel free to create a PR.
So with all due respect: No, I do not want to create a PR.
That's too bad, because in this case, your change is a lot easier to judge without needing domain knowledge (i.e. I would dare to merge it), and there are active maintainers (@mator +1). But if you don't want to, that's also ok. @mator if you want, feel free to create a PR.
Well, in that case and since @mator doesn't seem to have found the time yet, I made #873 (which you already reviewed while I was still writing here, thank you!)
stuck with work... and a test unit... probably going to extend it with a test unit later, sorry for the delay....
stuck with work...
No problem. Aren't we all?
and a test unit... probably going to extend it with a test unit later, sorry for the delay....
Ironically, tests were one of the reasons I didn't really feel like opening a PR, because I don't have much experience with testing and am unfamiliar with the test system used by Ansible, yet had the vague feeling that some people/projects would like to have new tests with every bugfix that would have caught this particular bug.
We usually only ask for tests for modules/plugins (1) which are new, or (2) which already have tests. Since this isn't a new plugin and it currently has no tests, there's no need to start coming up with tests... (Of course a PR will not get not merged because it adds tests ;) )
SUMMARY
When replacing a value in /etc/network/interfaces that contains, for example,
||
, the new line is garbage. This is caused by the old value being used directly in a regular expression here: https://github.com/ansible-collections/community.general/blob/4e56347fc1d79d8f0a1e8f663eca58ee17fb8e47/plugins/modules/system/interfaces_file.py#L287ISSUE TYPE
COMPONENT NAME
interfaces_file
ANSIBLE VERSION
CONFIGURATION
OS / ENVIRONMENT
Target Debian Buster, but probably irrelevant
STEPS TO REPRODUCE
EXPECTED RESULTS
/etc/network/interfaces:
ACTUAL RESULTS
/etc/network/interfaces: