ansible -how to pickup hostname and create self signed certificate

Vowner asked:

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

[[email protected] 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

  - 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

My answer:

You don’t need to echo anything to “get” the hostname. It’s already one of Ansible’s gathered facts, ansible_hostname. 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_hostname}}" -default_cert yes -pw password

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.