ansible - Ansible Playbook 将数组列表作为变量传递
问题描述
所以我们目前有一个创建目录 yml 并且它创建了 20 个左右的文件夹。我正在尝试简化它并传入具有不同模式和递归标志的文件夹。作为测试,我创建了这个。
- debug: msg="testing = {{ testing }}"
- name: "loop through list from a variable"
debug:
msg: "dest: {{ item.dest }}, mode: {{ item.mode }}, recurse: {{ item.recurse }}"
with_items: "{{ testing }}"
通常我们有这样的东西:
- name: Create Multiple Directories
file:
path: "{{ item.dest }}"
mode: "{{ item.mode }}"
recurse: "{{ item.recurse }}"
state: directory
with_items:
- { dest: '/local/path1', mode: '0775', recurse: yes }
- { dest: '/local/path2', mode: '0777', recurse: no }
所以我的问题是我们使用 AaaS 来传递信息以及如何设置参数。我们在网页上有一个 TextBox。我尝试了以下没有运气。
- { dest: '/local/path1', mode: '0775', recurse: yes }
- { dest: '/local/path2', mode: '0777', recurse: no }
和
{ dest: '/local/path1', mode: '0775', recurse: yes }
{ dest: '/local/path2', mode: '0777', recurse: no }
和
dest: '/local/path1', mode: '0775', recurse: yes
dest: '/local/path2', mode: '0777', recurse: no
我在所有情况下遇到的错误都表明“dest”不存在。是格式化还是我需要考虑其他一些事情?
解决方案
我没有代表发表评论,但我认为您在第一个示例中发送的 yaml 是一个列表,但是通过 HTTP 将 yaml 发送到 AaaS 很困难。您可以尝试发送 JSON Blob,这样您就可以发送:
[{"dest": "/local/path1", "mode": "0775", "recurse": true },
{"dest": "/local/path2", "mode": "0777", "recurse": false }]
这可能会让你的生活更轻松
编辑:删除单引号,因为文本框可能已经被解释为字符串
推荐阅读
- typescript - 如何使用联系人数据返回客户数据,如果客户没有联系人,则返回客户数据
- oauth-2.0 - 如何创建一个 FusionAuth 应用程序,其中包含许多具有范围的 oauth 客户端
- laravel - 如何使用 VueJS (+ Laravel) 自动显示模态
- opengl - GLSL 片段着色器中的 2D 颜色网格
- javascript - 查找恰好存在于一个数组中的最小值
- viber - 从 Viber 的键盘按钮图像中获取错误图像
- python - 是否可以在 pysimplegui 中创建一个文本框(InputText)来自动完成用户尝试输入的内容?
- excel - 如何将焦点设置到 IE 子页面来控制它
- mongodb - Mongo db - 如何通过一次查找从同一个集合中获取两个计数?
- reactjs - 将 React Navigation 用于屏幕内的导航器?