【发布时间】:2020-06-28 13:22:46
【问题描述】:
我已经尝试了很多方法来在 Ansible 中完成这项工作,但我仍然卡住了:/
所以,我必须从一个文件中读取凭据(用户名和密码):
file1: (dest: /home/usr/Desktop/file1.txt)
#this is a cred file
number= 8910334
user= xyz #(this maybe username=xyz also)
password= abc
读取文件内容后,我需要根据以下内容在找到带有“用户”和“密码”的 ('=') 符号的位置进行拆分:
用户密钥=用户
用户价值= xyz
密码键=密码
密码值= abc
file2: (dest: /home/usr/Desktop/file2.txt)
#Hi, I need credentials
school= spsg
user = #(this value may be blank or may be filled with some other entry or it may be xyz.user.name= )
password= #(this value may be blank or may be filled with some other entry or it may be xyz.password.value= )
现在,在文件 2 中,我希望将用户 =________ 值和密码 =________ 值替换为从文件 1 中提取的用户值和密码值。 (用户和密码的行号可能会有所不同,所以不要将行号分别固定为[1]和[2])
另外,除了file2,还有一些文件需要file1中的值,所以如果这个任务用循环来完成会更好。
请建议我使用可能的 YAML 代码来完成这项工作。谢谢:)
【问题讨论】: