首页 > 解决方案 > 无法将多行字符串(私有 ssh 密钥)存储为 ansible 中的变量

问题描述

我正在尝试将ssh私钥存储为ansible变量。

它在一个加密文件中,它或多或少像这样

my_private_key: |
-----BEGIN OPENSSH PRIVATE KEY-----

kd02ke0ke0k20ke0ke40430940943090494
[...]

Xekrfmfimimfimfeimiefmim4304309430943==

-----END OPENSSH PRIVATE KEY-----

但是,ansible执行失败如下:

ERROR! We were unable to read either as JSON nor YAML, these are the errors we got from each:
JSON: Expecting value: line 1 column 1 (char 0)

Syntax Error while loading YAML.
  could not find expected ':'

The error appears to be in '/Users/pantelis/path/to/my/encrypted/file': line 6, column 1, but may
be elsewhere in the file depending on the exact syntax problem.

我存储这个多行变量的方式有问题吗?

标签: ansible

解决方案


块值需要比键缩进更远。

my_private_key: |
  -----BEGIN OPENSSH PRIVATE KEY-----
  kd02ke0ke0k20ke0ke40430940943090494
  Xekrfmfimimfimfeimiefmim4304309430943==
  -----END OPENSSH PRIVATE KEY-----

推荐阅读