On 3/8/20 2:41 PM, Azir Guleroglu wrote:
> 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
>
> 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 }}'
> *
> *
>
>
>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
>
ansible-proje...@googlegroups.com <mailto:
ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/ansible-project/6f831b28-8ece-468e-bd00-05fe278443ed%40googlegroups.com
> <
https://groups.google.com/d/msgid/ansible-project/6f831b28-8ece-468e-bd00-05fe278443ed%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.