简体   繁体   English

ansible 从用户输入读取 openssl 公钥 (.pem) 内容并在服务器上创建文件

[英]ansible to read openssl public key (.pem) content from user input and create a file on server

I m basically creating a playbook for creating pkcs12 file where in it asks for public key(.pem) and private key.我基本上是在创建一个用于创建 pkcs12 文件的剧本,其中要求提供公钥(.pem)和私钥。 my private key is on server so i can pass location of file.我的私钥在服务器上,所以我可以传递文件的位置。 but my public key(.pem) is not residing on server nor i can copy paste from local.但我的公钥(.pem)不在服务器上,我也不能从本地复制粘贴。 so i want to create an ansible-playbook which can read public key content from user as a variable and create a file on the remote server to use in pkcs12 file creation.所以我想创建一个 ansible-playbook,它可以从用户那里读取公钥内容作为变量,并在远程服务器上创建一个文件以用于 pkcs12 文件创建。

my publickey content is spreaded across multiple lines like below.我的公钥内容分布在多行,如下所示。

-----BEGIN CERTIFICATE-----
(64-character alphanumeric content)
.
.
.
.
-----END CERTIFICATE-----

can you suggest simple way to achieve this.你能建议实现这一目标的简单方法吗? i am using copy module 'content' option, but unable to achieve this.我正在使用复制模块“内容”选项,但无法实现这一点。

  tasks:
  - name: copy content
    copy:
     content: "{{ my_pub_key }}"
     dest: /tmp/{{file}}.pem

ansible-playbook abc.yaml -e "my_pub_key=
-----BEGIN CERTIFICATE-----
.
.
.
.
-----END CERTIFICATE-----

"~ please suggest if there is any another way to achieve this? “〜请建议是否有其他方法可以实现这一目标?

Not exactly sure, what do you mean by below statement.不完全确定,下面的陈述是什么意思。 From the question, guessing nothing was written to the destination file.从问题中,猜测没有写入目标文件。

...but unable to achieve this... ...但无法实现这一目标...

Your task looks fine.你的任务看起来不错。 However, to pass multiline string as a parameter, add quote ( ' ) to define variable value like this.但是,要将多行字符串作为参数传递,请添加引号 ( ' ) 以像这样定义变量值。

$ ansible-playbook abc.yaml -e "my_pub_key='
-----BEGIN CERTIFICATE-----
.
.
.
.
-----END CERTIFICATE-----'"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM