-
Notifications
You must be signed in to change notification settings - Fork 10
Make sysconfig / defaults file configurable #65
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
Comments
I've been playing around with some regex. TLDRIf we only ever change that one option, not touching any other option via this role, we might have a solution that keeps existing options (e.g. set by the user manually) and adds this one in case it's needed. Simple solution, not as robustMy test looks like this:
Pre:
Post:
Problem: This way we can not change the path (/var/lib/elasticsearch/tmp) because it would would result in something like this
More complex solution, more robustThe other approach we can take is to
Example: - hosts: ansible-ubuntu22
become: yes
vars:
java_opt: "-Djna.tmpdir=/var/lib/elasticsearch/tmp"
tasks:
- name: Fetch contents of /etc/default/elasticsearch
slurp:
src: "/etc/default/elasticsearch"
register: "elasticsearch_defaults_file"
- name: Debug
vars:
full_line: "{{ elasticsearch_defaults_file.content | b64decode | split('\n') | select('match', '^ES_JAVA_OPTS=.*') | join }}"
old_options: "{{ full_line | regex_search('ES_JAVA_OPTS=\"(.*)\"', '\\1') | first }}"
new_options: "{{ java_opt + ' ' + ( old_options | regex_replace('-Djna\\.tmpdir=[^\\s]+ ?', '')) }}"
lineinfile:
path: "/etc/default/elasticsearch"
regexp: 'ES_JAVA_OPTS='
line: 'ES_JAVA_OPTS="{{ new_options }}"'
Set vars explained quickly: This example can deal with
But before I get too ahead of myself: what exactly do you mean by "configurable", @widhalmt? If we only ever need to change this one option and otherwise would (manually) edit the file, there should be no problem with the approach I layed out. We'd keep whatever is in the options and (re)add our single option. |
We need to change a line in
/etc/sysconfig/elasticsearch
or/etc/default/elasticsearch
for NETWAYS/ansible-role-elasticsearch#74 . The current impelementation is not very friendly for more upcoming changes.So either find a way to merge
ES_JAVA_OPTS
and use severallineinfile
or change the current implementation and go for a template. (Might be better but way more work due to possibly version dependent contents of the file)The text was updated successfully, but these errors were encountered: