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

Allow multiple options in ini_file #19536

Closed
wants to merge 0 commits into from
Closed

Allow multiple options in ini_file #19536

wants to merge 0 commits into from

Conversation

GheRivero
Copy link

@GheRivero GheRivero commented Dec 19, 2016

Some ini files will allow an option to appear several times
with different values (e.g. systemd services files)

Add a new option, 'unique', defaulting to yes, to specifie if
a option can appears once or multiples times.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

ini_file

ANSIBLE VERSION

2.4.0


SUMMARY

Options in a ini file can appear multiple times in the same section. Until now, only one was allowed, deleting the rest.

[default]
path=/usr/bin
path=/usr/sbin



This change is Reviewable

@ansibot
Copy link
Contributor

ansibot commented Dec 20, 2016

@ansibot ansibot added affects_2.3 This issue/PR affects Ansible v2.3 feature_pull_request module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. labels Dec 20, 2016
@bcoca
Copy link
Member

bcoca commented Dec 20, 2016

how does this interact with deletion and updates?

@bcoca bcoca added needs_info This issue requires further information. Please answer any outstanding questions. and removed needs_triage Needs a first human triage before being processed. labels Dec 20, 2016
@GheRivero
Copy link
Author

The behavior is exactly the same when unique=yes (default)
With unique: no, when updating, it simply adds a new option and checks that the (option, value) pair is not duplicated.
When deleting with unique=no, it deletes only the first option occurrence (same as with unique=yes)... but I'm thinking that maybe it should delete all the options occurrences.

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed needs_info This issue requires further information. Please answer any outstanding questions. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Dec 20, 2016
@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 Jan 2, 2017
@jimi-c jimi-c removed the plugin label Jan 4, 2017
@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. community_review In order to be merged, this PR must follow the community review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Jan 5, 2017
@ansibot ansibot added needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed community_review In order to be merged, this PR must follow the community review workflow. labels Jan 17, 2017
@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 Apr 11, 2017
@ansibot ansibot removed the needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html label May 23, 2017
@ansibot ansibot removed 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 May 23, 2017
@ansibot
Copy link
Contributor

ansibot commented May 23, 2017

The test ansible-test sanity --test validate-modules failed with the following error:

lib/ansible/modules/files/ini_file.py:0:0: E309 version_added for new option (unique) should be 2.4. Currently 2.3

click here for bot help

@ansibot ansibot added ci_verified Changes made in this PR are causing tests to fail. community_review In order to be merged, this PR must follow the community review workflow. and removed ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels May 23, 2017
@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 Jun 8, 2017
@ansibot ansibot added the support:community This issue/PR relates to code supported by the Ansible community. label Jun 29, 2017
@calfonso
Copy link
Contributor

cc @jpmens are you up for reviewing and/or testing this change out and let us know so we can take action on this?

choices: [ "yes", "no" ]
default: "yes"
description:
- If set to 'no', the option could appears several times in the section with diferent values.
Copy link
Contributor

Choose a reason for hiding this comment

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

please change the world could by may.

Copy link
Author

Choose a reason for hiding this comment

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

Done

@jpmens
Copy link
Contributor

jpmens commented Aug 1, 2017

Looks good to me. Small language nit in doc; if you'd please fix that.

@jpmens
Copy link
Contributor

jpmens commented Aug 2, 2017

shipit

@ansibot ansibot removed 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 Aug 3, 2017
@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 Aug 16, 2017
@ansibot ansibot added needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed community_review In order to be merged, this PR must follow the community review workflow. labels Sep 26, 2017
@ansibot ansibot added the new_contributor This PR is the first contribution by a new community member. label Oct 18, 2017
@ansibot ansibot removed the new_contributor This PR is the first contribution by a new community member. label Nov 3, 2017
@Scriptkiddi
Copy link

hey I was wondering in which ansible version i can expect this feature?

@ansibot ansibot added the new_contributor This PR is the first contribution by a new community member. label Jan 26, 2018
@ansibot ansibot added feature This issue/PR relates to a feature request. and removed feature_pull_request labels Mar 2, 2018
@StoneISStephan
Copy link

StoneISStephan commented May 14, 2018

When will this PR get merged?
I have multiple options with the same name, but different values, and they all must exist.
There are multiple valid values for the same option (they get fed to a selector).

Edit:

I tested this by manually merging the changes.
I see that I get unwanted behaviour when running the task again:

- name: Add PHP Memory Limits to panel.ini
  ini_file:
    path: "{{ plesk_panel_ini }}"
    section: 'php'
    option: "{{ item.option }}"
    value: "{{ item.value }}"
    state: present
    no_extra_spaces: yes
    create: yes
    unique: no
  with_items:
    - { option: 'settings.performance.memory_limit.values[]', value: '128M' }
    - { option: 'settings.performance.memory_limit.values[]', value: '256M' }
    - { option: 'settings.performance.memory_limit.values[]', value: '512M' }
    - { option: 'settings.performance.memory_limit.custom', value: 'false' }
  tags: plesk, plesk-configure, plesk-panel-ini

ansible-playbook output (-vv):

[php]
settings.general.open_basedir.default="none"
+settings.performance.memory_limit.values[]=256M
settings.performance.memory_limit.values[]=128M
settings.performance.memory_limit.values[]=512M
-settings.performance.memory_limit.values[]=256M
settings.performance.memory_limit.custom=false

For my use case, this is not an issue, but I can imaging that you'd only want to have "state changed" when there was an actual change.

This might be fixable if values got written to the bottom of a section, instead of at the beginning.
The module would then not even create a change in the first place.

Edit2:

From what I see, the code does not really know where a section ends.

Would be nice if the code extracted the current section ini_lines
then we could use:

option_changed = newline not in section_ini_lines

in order not to change values that are already defined in all sections

[customer1]
allowed_values=128M
allowed_values=256M
[customer2]
allowed_values=128M
allowed_values=256M
allowed_values=512M

if we'd run a playbook that defines for customer1 the permissions that are already granted,
we'd like to have Ansible just return that no changes were needed.
In order words, the Ansible module should know that in section [customer1] these values are already set.
Instead of changing the above to:

[customer1]
allowed_values=256M
allowed_values=128M
[customer2]
allowed_values=128M
allowed_values=256M
allowed_values=512M

on the second call of ini_file module, as the module writes to <section_index + 1>
and then removes the last (duplicate) entry.

@StoneISStephan
Copy link

There is also a typo in the PR:

mgs = 'option added'

should be:

msg = 'option added'

msg = 'option changed'
ini_lines[index] = newline
else:
mgs = 'option added'

Choose a reason for hiding this comment

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

should be:

msg = 'option added'

@GheRivero
Copy link
Author

closed my mistake...

@ansible ansible locked and limited conversation to collaborators May 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.3 This issue/PR affects Ansible v2.3 feature This issue/PR relates to a feature request. module This issue/PR relates to a module. needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. new_contributor This PR is the first contribution by a new community member. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. support:community This issue/PR relates to code supported by the Ansible community.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants