ansible - Ansible:delegate_to 组无法正常工作
问题描述
在我的 dockerized Ansible 2.8 中,我试图更改已使用动态添加到清单的远程主机上的 ssh 设置add_host
剧本.yml
# configure new VMs
- name: Configure new Azure VM
hosts: localhost
connection: local
gather_facts: no
roles:
- az-vm-configure
tags:
- az-vm-configure
主要的.yml
- name: Configure inventory
include: inventory.yml
- name: Configure sshd
include: sshd.yml
delegate_to: '{{ groups.new[0] }}'
当我使用以下构造时它工作正常:delegate_to: '{{ groups.new[0] }}'
但是当我尝试为这样的组中的所有主机实现它时:
delegate_to: '{{ item }}'
with_items: "{{ groups['new'] }}"
我的任务忽略了上面的构造并尝试在本地主机上执行任务: 任务执行结果
在这种情况下似乎delegate_to: '{{ item }}'
不起作用。有人可以提出任何解决方法吗?
解决方案
当我尝试如上所述放入 main.yml 时,我给出了一个错误
hosts
无论如何这ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.
是我的解决方案:
剧本.yml
# configure VM
- name: Add new VM to inventory
hosts: localhost
connection: local
gather_facts: no
tasks:
- include_role:
name: az-vm-configure
tasks_from: inventory.yml
tags:
- az-vm-configure
- name: Configure new Azure VM
hosts: new
gather_facts: no
tasks:
- include_role:
name: az-vm-configure
tasks_from: sshd.yml
tags:
- az-vm-configure
角色/az-vm-configure/tasks/main.yml
- include_tasks: '{{ tasks }}'
with_items:
- inventory.yml
- sshd.yml
loop_control:
loop_var: tasks
推荐阅读
- algorithm - 二叉搜索树中不成功搜索的最佳情况复杂度
- excel - LoadPicture 方法失败
- c# - 不同的“翻译”JsonProperty 名称
- javascript - ckeditor 所需文件未加载
- html - Nuxt:标题功能不适用于标题或元标记
- scala - 尝试运行 sbt 时未解决的依赖关系
- html - XSL/XPath/XML 问题
- c# - 如何在选择框选项更改时过滤 ASP.NET MVC 视图中的 C# DataTable
- java - SimpleAsyncTaskExecutor 只启动 8 个线程
- python - 使用 imshow 绘制具有小模式的大数据隐藏数据