我正在尝试制作一个循环遍历目录中文件数量的剧本,然后在另一个剧本中使用这些文件。 我现在的剧本:
---
- name: Run playbooks for Raji's testing
register: scripts
roles:
- prepare_edge.yml
- prepare_iq.yml
- scriptor.yml
with_fileglob: ~/ansible/test_scripts/*
~
当我运行它不起作用时,我尝试使用“ register:scripts”在scriptor.yml中创建要引用的变量,但是剧本再次失败。您可以提供的任何建议或帮助将不胜感激。 谢谢!
P.S。我对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"
P.S.S 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
答案 0 :(得分:0)
您收到一条错误消息,告诉您无法在Playbook中运行register
。
您可以通过在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
参考
How can Ansible "register" in a variable the result of including a playbook?