- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试加密一些密码,但想仅加密字符串的一部分而不是整个文件。因此,有一个命令 ansible-vault encrypt_string 可以为您提供加密的输出,但是当我将其添加到我的 .yaml 剧本中时,它无法解密。
用于加密简单密码的命令:
ansible-vault encrypt_string 'Test123!' --name 'ansible_password'
结果:
ansible_password: !vault | $ANSIBLE_VAULT;1.1;AES256 30333733643939646130396638646138636338636162316536313236666334656338306634353434 3132326265313639623039653261336265343733383730340a663565323932636138633365386332 36363534326263326633623238653464376637646632363839313464333830363436643561626534 6338613837393539350a383962663766373466376138376666393639373631313861663866333663 6137 Encryption successful
^
formatting is a little bit clunky with long strings
所以我尝试将这个值放入我的剧本中,如下所示:
---
- name: Copy needed files to target machine
hosts: prod
vars:
ansible_user: test_admin
ansible_password: !vault $ANSIBLE_VAULT;1.1;AES256;303337336439396461303966386461386363386361623165363132366663346563383066343534343132326265313639623039653261336265343733383730340a663565323932636138633365386332363635343262633266336232386534643766376466323638393134643338303634366435616265346338613837393539350a3839626637663734663761383766663936393736313138616638663336636137
ansible_connection: winrm
ansible_winrm_transport: credssp
ansible_winrm_server_cert_validation: ignore
tasks:
- name: Copy test
win_copy:
src: /etc/winmachines/hosts
dest: C:\test\
然后我想用命令执行剧本:
ansible-playbook copy.yaml -i hosts.ini
结果:
PLAY [Copy needed files to target machine] ********************************************************************************************************
TASK [Gathering Facts] ****************************************************************************************************************************
fatal: [10.5.17.5]: FAILED! => {"msg": "Attempting to decrypt but no vault secrets found"}
to retry, use: --limit @deleted
PLAY RECAP ****************************************************************************************************************************************
10.5.17.5 : ok=0 changed=0 unreachable=0 failed=1
当我使用参数 --ask-vault-password 运行 playbook 时:
ansible-playbook copy.yaml -i hosts.ini --ask-vault-pass
PLAY [Copy needed files to target machine] ********************************************************************************************************
TASK [Gathering Facts] ****************************************************************************************************************************
[WARNING]: There was a vault format error: Vault vaulttext format error: need more than 1 value to unpack
fatal: [10.5.17.5]: FAILED! => {"msg": "Vault vaulttext format error: need more than 1 value to unpack"}
to retry, use: --limit @deleted
PLAY RECAP ****************************************************************************************************************************************
10.5.17.5 : ok=0 changed=0 unreachable=0 failed=1
我尝试过以各种方式加密输出,但每次都因为这个问题或语法问题而失败。
当以从输出传递的方式放入时,我收到如下语法错误:
ERROR! Syntax Error while loading YAML.
could not find expected ':'
The error appears to have been in : line 8, column 11, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
$ANSIBLE_VAULT;1.1;AES256
34323264326266303364656561616663306566356636616238623931613032343131643839336338
^ here
当所有内容都在同一行时,删除“|”收到此错误:
TASK [Gathering Facts] ****************************************************************************************************************************
fatal: [10.5.17.5]: FAILED! => {"msg": "AES256 343232643262663033646565616166633065663566366162386239316130323431316438393363383331346231343361386432666461646639386135666335380a373862336531613034393262653432313038303432636536313139353932356637343139393938666536383061383233613136643063353761386339323562640a3963306632393865613237666364386566623938356465336363613163646338 cipher could not be found"}
有什么想法吗?
最佳答案
您的格式不正确。由 ansible-vault encrypt_string 'Test123!' 给出的格式--name 'ansible_password'
是您应该使用的。
仅供引用, https://github.com/ansible/ansible/blob/devel/lib/ansible/parsing/vault/init.py#L153 。 Vault 解析器正在寻找由 splitlines() 确定的位于第一行的 $ANSIBLE_VAULT;1.1;AES256
(或类似的;vaulttext_envelope)。删除换行符打破了这一期望。
在 encrypt_string
的输出中,语法完全正确,可以粘贴到您的剧本中。 |
(管道字符)在 yaml 中具有特殊含义。它是一个保留换行符的多行 block 。它应该是该行的最后一个字符。使用多行 block 时保持一致的缩进。因为剩余部分是在 https://github.com/ansible/ansible/blob/devel/lib/ansible/parsing/vault/init.py#L165 上join
的,您不需要在密文本身中保留新行。
这意味着以下任何一项都应该有效:
ansible_password: !vault |
$ANSIBLE_VAULT;1.1;AES256
30333733643939646130396638646138636338636162316536313236666334656338306634353434
3132326265313639623039653261336265343733383730340a663565323932636138633365386332
36363534326263326633623238653464376637646632363839313464333830363436643561626534
6338613837393539350a383962663766373466376138376666393639373631313861663866333663
6137
ansible_password: !vault |
$ANSIBLE_VAULT;1.1;AES256
303337336439396461303966386461386363386361623165363132366663346563383066343534343132326265313639623039653261336265343733383730340a663565323932636138633365386332363635343262633266336232386534643766376466323638393134643338303634366435616265346338613837393539350a3839626637663734663761383766663936393736313138616638663336636137
ansible_password: !vault "$ANSIBLE_VAULT;1.1;AES256\r\n303337336439396461303966386461386363386361623165363132366663346563383066343534343132326265313639623039653261336265343733383730340a663565323932636138633365386332363635343262633266336232386534643766376466323638393134643338303634366435616265346338613837393539350a3839626637663734663761383766663936393736313138616638663336636137"
请注意,在上一个示例中,我没有使用管道并使用 \r\n
作为换行符。
另请引用:https://yaml-multiline.info/
为了清晰起见,添加完整示例:
---
- name: Copy needed files to target machine
hosts: prod
vars:
ansible_user: test_admin
ansible_password: !vault |
$ANSIBLE_VAULT;1.1;AES256;
30333733643939646130396638646138636338636162316536313236666334656338306634353434
30333733643939646130396638646138636338636162316536313236666334656338306634353434
3132326265313639623039653261336265343733383730340a663565323932636138633365386332
36363534326263326633623238653464376637646632363839313464333830363436643561626534
6338613837393539350a383962663766373466376138376666393639373631313861663866333663
6137
## Notice indentation above
## the block started with | will end when indentation changes.
ansible_connection: winrm
ansible_winrm_transport: credssp
ansible_winrm_server_cert_validation: ignore
顺便说一句,选择制表符或空格,但不要同时使用两者。我一般建议使用空格,但对于 python 和 yaml 则更是如此。如果您的编辑器/IDE 不支持语法突出显示,您应该切换到具有语法突出显示功能的编辑器/IDE。并获取某种 yaml linter。 yamllint.com 在短期内可以工作,但从长远来看,您应该获得一些自动的东西并内置到您的编辑器中。
关于ansibleVault加密字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55849706/
我正在使用框架的对象编写一个用于加密/解密的简单库。方法如下: public static byte[] Encrypt(byte[] key, byte[] vector, byte[] input
据我所知,RIM Crypto API 似乎只提供用于对称加密 (3Des) 的 PKCS5 填充模式。我正在使用 JDE 4.6.0。 我正在尝试为黑莓应用程序提供密码学,该应用程序需要与已经使用标
我已经获得了用于加密的 Java 实现,但遗憾的是我们是一家 .net 商店,我无法将 Java 整合到我们的解决方案中。可悲的是,我也不是 Java 专家,所以我已经为此苦苦挣扎了几天,我想我终于可
我正在尝试使用 KMS 和 AWS 加密 SDK 加密数据。查看 AWS documentation 中提供的示例,似乎没有地方可以明确设置数据 key 。 我找到了 EncryptionMateri
我目前有一个用于为我的网站制作哈希的代码,该代码使用 SALT 进行哈希处理,因此密码是不可逆的...... 目前它是 100% 为我的网站工作,它是使用 ASP.NET(C#) 编码的 这是我的代码
我想要做的是在 javascript 中生成一个 key 对,并在 PHP 中使用这些加密,然后用 JS 解密。 我在附加的代码中有两个问题 它不会从装甲文本块重新加载私钥 并且它不会解密 PHP 加
在进行密码哈希时,我有以下 node.js 代码。 body.password = covid@19 salt = "hello@world" body.passwordhex = crypto.cr
我想知道的是在配置文件中加密连接字符串的明确方法。以下是我的问题: 使用机器级加密,访问我的服务器的任何人都不能编写一个小的 .Net 程序来读取连接字符串的内容吗? 如果我将我的应用程序部署到企业环
我知道 rsync 可以在文件传输期间启用/禁用 ssh 加密协议(protocol)。那么,如果 ssh 加密协议(protocol)被禁用了,是不是意味着 rsync 根本不做任何加密呢? 另外,
脚本必须搜索网页内的字符串。但该脚本不应显示它正在搜索的字符串。我的意思是搜索字符串应该采用加密格式或任何其他格式。但如果没有该搜索字符串,则不应显示网页或应在页面上显示错误。 我要开发一个插件。如果
我正在尝试加密 MySQL 上的某些字段。我正在使用 TPC-DS 的 v2.8 版本,并尝试在客户地址表的某些列上使用 AES。知道如何加密字段的所有行吗?我尝试使用 UPDATE customer
我需要一个简单的 javascript 函数,它允许我使用 key 加密 textarea 数据( key 是存储为散列 session 变量的用户密码,由 PHP 打印到字段中) 我基本上希望在用户
如何在 JavaScript 中散列/加密字符串值?我需要一种机制来隐藏 localStorage/cookie 中的一些数据吗? 这与安全问题有关,但我想为我的数据提供一些保护。 最佳答案 有很多
我有一个程序,其中数据库的密码由远程用户设置。该程序将用户名和密码保存到 xml 文件中的加密字符串中,否则应该是人类可读的。现在,这工作正常,我使用带有 key 的 C# DES 加密,它被加密和解
Kotlin 中是否有任何关于椭圆曲线加密的信息? 用于生成 key 对和加密、解密消息。 关于这个主题的信息很少甚至没有。 例如,我想实现 ECC P-521 椭圆曲线。 是否可以在 Kotlin
所以我知道 MD5 在技术上是新应用程序的禁忌,但我随机想到了这个: 自 md5($password); 不安全,不会 md5(md5($password)) 是更好的选择?我使用它的次数越多,它会变
我一直在努力使用 crypto_secretbox_easy() 在 libsodium 中加密/解密一些数据| .我似乎找不到关于使用的任何好的文档。 我想从用户那里获取密码,用它来以某种方式制作
我正在做一个加密项目 视频,我对这个程序有几个问题。 我用命令转码mp4至HLS与 ts段持续时间约为 10 秒。 首先,我需要使用数据库中的 key 加密这些视频。然而, 我不知道是否使用 ffmp
我有一个加密/复制保护问题。 我正在为使用加密狗的公司编写应用程序。请不要告诉我软件保护是没有用的,或者我应该让它自由地飞向空中,或者我花任何时间这样做都是浪费;这不是关于软件保护有效性的哲学问题,更
我对 有一个疑问VIM 加密 key . 我有一个文本文件,我使用加密该文件 :X 现在,加密 key 的存储位置(路径)。 无论是存储在单独的文件中还是存储在文本文件本身中。 如果我打开文件,它会询
我是一名优秀的程序员,十分优秀!