大网数据广告活动
服务器运维问答

ansible -how to pickup hostname and create self signed certificate

· 52CE 我爱测

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 sh…

问题原文

原帖链接 · Vowner · CC BY-SA 4.0

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

已采纳解答

原帖链接 · Michael Hampton · CC BY-SA 4.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-11-27)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。