Bastien D
Bastien D

Reputation: 1465

How to get dnsdomainname value in ansible

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

Upvotes: 0

Views: 1215

Answers (1)

D.Fitz
D.Fitz

Reputation: 531

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

Upvotes: 1

Related Questions