Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ansible读取csv文件并加密密码,将命令输出到文件_Ansible - Fatal编程技术网

Ansible读取csv文件并加密密码,将命令输出到文件

Ansible读取csv文件并加密密码,将命令输出到文件,ansible,Ansible,我有一个包含ip地址和密码的csv文件。这些密码需要加密并写入文件 这就是我迄今为止所尝试的: -名称:读取csv文件 阅读(csv): 路径:文件/ww.csv 字段名:ip,密码 分隔符:',' 注册:路由器 委托给:localhost -名称:加密密码 命令:“ansible vault encrypt_字符串--vault密码文件密码'{{router.password}}}'--名称'password'” 循环:“{{routers.list}}” 回路控制: 循环变量:路由器 寄存器

我有一个包含ip地址和密码的csv文件。这些密码需要加密并写入文件

这就是我迄今为止所尝试的:

-名称:读取csv文件
阅读(csv):
路径:文件/ww.csv
字段名:ip,密码
分隔符:','
注册:路由器
委托给:localhost
-名称:加密密码
命令:“ansible vault encrypt_字符串--vault密码文件密码'{{router.password}}}'--名称'password'”
循环:“{{routers.list}}”
回路控制:
循环变量:路由器
寄存器:“输出”
委托给:localhost
-名称:写入文件
副本:
内容:“{output.stdout}”
dest:“/tmp/{{router.ip}}.yaml”
循环:“{{routers.list}}”
回路控制:
循环变量:路由器
委托给:localhost
我想使用
output.stdout
,但出现以下错误:

TASK [robustel : write file] *********************************************************************************************************************************
fatal: [10.41.1.161]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'stdout'\n\nThe error appears to be in '/ansible/roles/routers/tasks/create_var_files.yaml': line 20, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: write file\n  ^ here\n"}

如何解决此问题?

您正在使用循环在任务上注册变量。这将更改中所述的数据结构。调试
输出
会给你一个线索

output.results
是一个列表,其中每个元素都包含一个
stdout
键(例如,第一个是
output.results.0.stdout
)。此外,每个元素还包含一个
键,其中包含已注册的循环中的原始元素

修改上一个任务(如下面所示)将获得预期结果:

-名称:写入文件
副本:
内容:“{output_result.stdout}”
dest:“/tmp/{output_result.item.ip}}.yaml”
循环:“{output.results}}”
回路控制:
循环变量:输出结果
委托给:localhost