ansible - ansible:循环目录并在另一个剧本中引用该文件
问题描述
我正在尝试制作一个循环遍历目录中文件数量的剧本,然后在另一个剧本中使用这些文件。我现在的剧本:
---
- name: Run playbooks for Raji's testing
register: scripts
roles:
- prepare_edge.yml
- prepare_iq.yml
- scriptor.yml
with_fileglob: ~/ansible/test_scripts/*
~
当我运行它时它不起作用,我尝试“注册:脚本”来创建一个变量以在 scriptor.yml 中引用,但剧本再次失败。您可以提供的任何建议或帮助将不胜感激。谢谢!
PS我对ansible超级陌生
这是scriptor.yml
---
- hosts: all
tasks:
- name: Create directory
command: mkdir /some/path/
- name: If file is a playbook
copy:
src: "{{ scripts }}"
dest: /some/path/
when: "{{ scripts }}" == "*.yml"
- name: if file is a script
shell: . ${{ scripts }}
when: "{{ scripts }}" == "*.sh"
PSS prepare_edge.yml 和 prepare_iq.yml 不引用任何内容,只需要在 scriptor.yml 之前的循环中调用
这是错误:
ERROR! 'register' is not a valid attribute for a Play
The error appears to have been in '/Users/JGrow33/ansible/raji_magic_playbook.yml': line 3, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: Run playbooks for Raji's testing
^ here
解决方案
您收到的错误消息是告诉您无法register
在 Playbook 中运行。
您可以通过在 scriptor.yml 文件中执行以下操作来完成您正在寻找的内容:
- hosts: all
tasks:
- name: Create directory
command: mkdir /some/path/
- name: If file is a playbook
copy:
src: "{{ item }}"
dest: /some/path/
with_fileglob: ~/ansible/test_scripts/*.yml
- name: if file is a script
shell: . ${{ item }}
with_fileglob: copy:
src: "{{ item }}"
dest: /some/path/
with_fileglobe: ~/ansible/test_scripts/*.sh
参考
推荐阅读
- r - R用括号分割字符串
- java - 在 Java 中的另一个对象中实例化一个对象(组合与继承)
- r - 如何使用数据框中另一列的数据在 R 中命名文件下载?
- java - 关于对csv文件中一行的元素进行排序并将其存储到不同的Arraylists中
- python-3.x - 如何安装缺少的 opencv 模块?
- idris - 在 Idris 中检查向量的类型
- php - PHP路由系统altorouter不工作
- javascript - onClick array.push 覆盖之前的元素 React
- c++ - 按值从向量中获取对象
- python - 将 Google API 安装到 AWS Cloud9:“没有名为 'google.api_core' 的模块”