Tony_Wong
(Tony Wong)
January 31, 2023, 8:41pm
1
trying to add multiple ntp servers to chrony.conf
name: add line
lineinfile:
backup: no
backrefs: no
state: present
path: “{{ file_path }}”
insertafter: “{{ line.replace_with }}”
line: “{{ line.line_to_add }}”
with_items:
{ search: “{{ line.replace_with }}”, add: “{{ line.line_to_add }}” }
but it only adds it as single line
any idea?
vars
line:
line_to_add:
Where are you sourcing the “lines” you want to add to the file? What variable contains that list? You reference “line”. What is the format/type of that variable?
name: add line
lineinfile:
backup: no
backrefs: no
state: present
path: “{{ file_path }}”
insertafter: “{{ item.search }}”
line: “{{ item.add }}”
with_items:
{ search: “{{ line.replace_with }}”, add: “{{ line.line_to_add }}” }
Walter
Tony_Wong
(Tony Wong)
January 31, 2023, 8:55pm
4
the source is in my vars.yml file
line:
line_to_add:
variable is line_to_add
Tony_Wong
(Tony Wong)
January 31, 2023, 9:07pm
5
here is my output
[WARNING]: The value “[‘server ntp1.domain.com iburst’, ‘server ntp2.domain.com iburst’, ‘server ntp3.domain.com iburst’]” (type list) was
converted to “u”[‘server ntp1.domain.com iburst’, ‘server ntp2.domain.com iburst’, ‘server ntp3.domain.com iburst’]“” (type string). If this
does not look like what you expect, quote the entire value to ensure it does no
This is a LIST all by itself. Its reference is line.line_to_add.
line_to_add:
You have no value set for “replace_with”. What sets that?
Walter
Tony_Wong
(Tony Wong)
January 31, 2023, 9:17pm
7
its this
line:
line_to_replace: “server ntp1a.domain.com iburst”
replace_with: “#server ntp1a.domain.com iburst”
line_to_add:
Tony_Wong
(Tony Wong)
January 31, 2023, 9:26pm
8
if it was only 1 line then its fine
line_to_add: “server ntp1.domain.com iburst”
but not multiple lines