I tried to change one line in a file with lineinfile command, but it looks like this command does not resolve variables. See my playbook snippet below
#in my playbook, {{ kibana_doc_root }}, {{ kibana_version }}, {{kibana_config_file}}, {{elasticsearch_URL}}, {{ elasticsearch_port }} have been defined
The following snippet can successfully change the file content in config.js, but {{elasticsearch_URL}} is not resolved (i.e. the line shows {{elasticsearch_URL}} as is):
name: Replace the URI of the ElasticSearch service in config.js on Kibana server
lineinfile:
dest=/var/www/kibana/kibana-3.0.0milestone4/config.js
regexp=“(elasticsearch.* "http.*)$”
state=present
line="elasticsearch’:’ " {{ elasticsearch_URL }}:{{ elasticsearch_port }} " "
Just FYI in case that other folks may find this helpful later.
I took Michael’s hint, and changed the error_on_undefined_vars from False to True, which basically returns an explicit error if there exists a missing variable, as follow.
myproject_foler/.ansible.cfg
#error_on_undefined_vars = False
error_on_undefined_vars = True
And I found that the original error was caused by one missing variable in the lineinfile command, {{ elasticsearch_URL }}. Once I add those variables in my vars file, everything start working
In short, lineinfile does take varaiables and it works perfectly
My only slight complaint is that the error message was not as related to the root cause as it could be.