2

i have working command for creating self signed certificate for IHS server's .kdb file and i was trying to use the same command through ansible. Here my aim is that ansible should detect the hostname of application servers and should use that name for the "-dn" of the command. Below is the working command

[root@myhost bin]# ./gskcmd -cert -create -db /opt/myapp/key.kdb -label IHS -expire 3650 -size 2048 -dn "CN=myserverFQDN" -default_cert yes -pw password

but below is my play and its giving syntax error

tasks:
  - name: get hostname
    shell: echo $HOSTNAME
    register: hostname

  - name: create self signed certificate for IHS
    command: /opt/myapp/bin/gskcmd -cert -create -db /opt/myapp/key.kdb -label IHS -expire 3650 -size 2048 -dn "CN={{ hostname}}" -default_cert yes -pw password
Vowner
  • 23
  • 1
  • 3
  • 1
    Actually posting the complete and error message (at a suitable debug level and preferably as code but even screenshot would help) is usually a good thing. - Is the hostname what you need (and not the FQDN)? Why don't you use `{{ ansible_hostname }}` instead of running a shell command to determine the hostname? – HBruijn Nov 27 '18 at 15:14
  • Thanks HBruijin, it helped me to resolve the issue – Vowner Nov 28 '18 at 06:43

1 Answers1

3

You don't need to echo anything to "get" the hostname. It's already one of Ansible's gathered facts, ansible_nodename. You just need to use it.

    command: /opt/myapp/bin/gskcmd -cert -create -db /opt/myapp/key.kdb -label IHS -expire 3650 -size 2048 -dn "CN={{ansible_nodename}}" -default_cert yes -pw password

Depending on what you are doing, you may need to use one of the alternate facts, ansible_hostname or inventory_hostname.

These variables are set as follows:

  • inventory_hostname is the hostname as it is set in your Ansible inventory. For example www.internal-name.example.
  • ansible_hostname is the unqualified hostname as reported by the system. For example www.
  • ansible_nodename is the fully qualified hostname as reported by the system. For example www.example.com.
Michael Hampton
  • 237,123
  • 42
  • 477
  • 940