Question:
I want to change one line of my code in file /var/www/kibana/config.js during installation from
1 2 |
elasticsearch: "http://"+window.location.hostname+":9200" |
to
1 2 |
elasticsearch: "http://192.168.1.200:9200" |
Here I tried to use lineinfile to do that as show below
1 2 3 4 5 6 7 8 |
- name: Comment out elasticsearch the config.js to ElasticSearch server lineinfile: dest=/var/www/kibana/config.js backrefs=true regexp="(elasticsearch.* \"http.*)$" line="elasticsearch\: \" {{ elasticsearch_URL }}:{{ elasticsearch_port }} \" " state=present |
I have set variables of {{elasticsearch_URL}}
and {{elasticsearch_port}}
to http://192.168.1.200
and 9200
, respectively.
Here is the error message I met:
1 2 3 4 5 6 7 |
ERROR: Syntax Error while loading YAML script, /Users/shuoy/devops_workspace/ansible_work/logging-for-openstack/roles/kibana/tasks/Debian.yml Note: The error may actually appear before this position: line 29, column 25 regexp="(elasticsearch.* \"http.*)$" line="elasticsearch\: \" {{ elasticsearch_URL }}:{{ elasticsearch_port }} \" " ^ |
Answer:
you need to enclose the entire line in "
, where :
appears.
1 2 3 4 5 6 7 |
lineinfile: 'dest=/var/www/kibana/config.js backrefs=true regexp="(elasticsearch.* \"http.*)$" line="elasticsearch\: \ {{ elasticsearch_URL }}:{{ elasticsearch_port }} \ " state=present' |