Ansible:将_委派给工作不正常的小组
在我的Docked Ansible 2.8中,我正在尝试使用Ansible:将_委派给工作不正常的小组,ansible,ansible-inventory,Ansible,Ansible Inventory,在我的Docked Ansible 2.8中,我正在尝试使用add\u host playbook.yml main.yml 当我使用以下构造时,它工作得很好:delegate_to:“{{groups.new[0]}” 但当我试图为组中的所有主机实现此功能时,如下所示: delegate_to: '{{ item }}' with_items: "{{ groups['new'] }}" 我的任务忽略上面的构造,并尝试在本地主机上执行任务: 似乎委托给:{{item}}在这种情况下不起作用
add\u host
playbook.yml
main.yml
当我使用以下构造时,它工作得很好:delegate_to:“{{groups.new[0]}”
但当我试图为组中的所有主机实现此功能时,如下所示:
delegate_to: '{{ item }}'
with_items: "{{ groups['new'] }}"
我的任务忽略上面的构造,并尝试在本地主机上执行任务:
似乎委托给:{{item}}
在这种情况下不起作用。
有人能提出解决办法吗
Q:“动态使用添加主机”
答:可以用创建的“新”主机组开始下一个游戏
- hosts: new
tasks:
- name: Configure sshd
include: sshd.yml
Q:“动态使用添加主机”
答:可以用创建的“新”主机组开始下一个游戏
- hosts: new
tasks:
- name: Configure sshd
include: sshd.yml
如上所述,当我试图将
hosts
放在main.yml中时,我给出了一个错误
错误!在任务中未检测到任何操作。这通常表示模块名称拼写错误或模块路径不正确。
无论如何,我的解决方案是:
playbook.yml
角色/az-vm-configure/tasks/main.yml
如上所述,当我试图将
hosts
放在main.yml中时,我给出了一个错误
错误!在任务中未检测到任何操作。这通常表示模块名称拼写错误或模块路径不正确。
无论如何,我的解决方案是:
playbook.yml
角色/az-vm-configure/tasks/main.yml
主机
不是一个模块。请参阅。主机
不是模块。看。
- name: Configure sshd
include: sshd.yml
delegate_to: '{{ groups.new[0] }}'
- hosts: new
tasks:
- name: Configure sshd
include: sshd.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
- include_tasks: '{{ tasks }}'
with_items:
- inventory.yml
- sshd.yml
loop_control:
loop_var: tasks