One issue about ansible_host with ansible 2.0, when I use lineinfile module.

When I use ansible_host in lineinfile module with ansible 2.0, I get ansible_host=“”. But in debug module, I can get exact host name by ansible_host. Is it a ansible 2.0 bug?
Actually, when I used ansible_ssh_host with ansible 1.9, it was OK.

My tasks are:

  • debug: msg=“ansible_host is {{ ansible_host }}”

  • name: Configure SonarQube host, context and port.
    lineinfile:
    dest: /usr/local/sonar/conf/sonar.properties
    regexp: “{{ item.regexp }}”
    line: “{{ item.line }}”
    with_items:

  • regexp: “^sonar.web.host”
    line: “sonar.web.host={{ ansible_host }}”

  • regexp: “^sonar.web.port”
    line: “sonar.web.port={{ sonar_http_port }}”

  • regexp: “^sonar.web.context”
    line: “sonar.web.context={{ sonar_http_context }}”

  • regexp: “^sonar.search.port”
    line: “sonar.search.port=0”

The tasks result is:

TASK [sonar : debug] ***********************************************************

ok: [controller] => {
“msg”: “ansible_host is 192.168.33.10”
}

TASK [sonar : Configure SonarQube host, context and port.] *********************

ok: [controller] => (item={u’regexp’: u’^sonar.web.host’, u’line’: u’sonar.web.host=‘})
ok: [controller] => (item={u’regexp’: u’^sonar.web.port’, u’line’: u’sonar.web.port=9000’})
ok: [controller] => (item={u’regexp’: u’^sonar.web.context’, u’line’: u’sonar.web.context=‘})
ok: [controller] => (item={u’regexp’: u’^sonar.search.port’, u’line’: u’sonar.search.port=0’})