using ansible facts in key value

Hello,

I try to use ansible facts in variable file but i get below error. Anyone how any idea how can i use my variable in to the playbook

fatal: [ANSIBLET01]: FAILED! => {“ansible_facts”: {}, “ansible_included_var_files”: , “changed”: false, “message”: “Syntax Error while loading YAML.\n found unacceptable key (unhashable type: ‘AnsibleMapping’)\n\nThe error appears to be in ‘/etc/ansible/yml/AzirPlaybooks/install/elk/elkvar.yml’: line 1, column 12, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\nhostname: {{ ansible_hostname }}\n ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes. Always quote template expression brackets when they\nstart a value. For instance:\n\n with_items:\n - {{ foo }}\n\nShould be written as:\n\n with_items:\n - "{{ foo }}"\n”}

My var file.

cat elkvar.yml
hostname: {{ ansible_hostname }}
network: {{ ansible_default_ipv4.address }}
transport: {{ ansible_default_ipv4.address }}

My part of playbook.

tasks:

  • name: include dynamic variables
    include_vars: elkvar.yml

  • name: replace security
    lineinfile:
    path: /etc/elasticsearch/elasticsearch.yml
    insertafter: ‘#node.name: node-1’
    line: ‘node.name: “{{ hostname }}”’

  • name: replace security
    lineinfile:
    path: /etc/elasticsearch/elasticsearch.yml
    insertafter: ‘network.host: 192.168.0.1’
    line: ‘network.host: {{ network }}’

  • name: replace security
    lineinfile:
    path: /etc/elasticsearch/elasticsearch.yml
    insertafter: ‘http.cors.allow-origin’
    line: ‘transport.host: {{ transport }}’

Hello,

I try to use ansible facts in variable file but i get below error. Anyone how any idea how can i use my variable in to
the playbook

Actually anyone who reads the error message carefully ... you need double quotes around the curly braces.

hostname: "{{ ansible_hostname }}"

Regards
        Racke

Hello Stefan

I tried it before in to the playbook. But now i did in var file and its work. Thanks

8 Mart 2020 Pazar 16:47:24 UTC+3 tarihinde Stefan Hornburg (Racke) yazdı: