0

I need dnsdomainname value in ansible variable.

$echo $(dnsdomainname)

To build http_proxy value with Ansible playbook, i need dnsdomainname value in local variable.

Thanks

Bastien D
  • 1,395
  • 2
  • 14
  • 26
  • 1
    Does this answer your question? [Ansible - accessing local environment variables](https://stackoverflow.com/questions/21422158/ansible-accessing-local-environment-variables) – sorin Nov 14 '19 at 06:21

1 Answers1

1

Here is a great discussion on importing environment variables into your playbook.

Ansible - accessing local environment variables

This documentation is for setting the variables in your inventory file.

https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html

I hope that helps.

EDIT:
@sorin's answer above should solve your problem.

{{ ansible_env.dnsdomainname }}

You can also use the module 'shell' to execute any command you want on the remote host.

- host {{ hosts }}
  gather_facts: "yes"

tasks:
 - shell: 'echo $dnsdomainname'
   register: dnsdomainname

 - debug:
     var: dnsdomainname
D.Fitz
  • 493
  • 5
  • 16