Ansible:ansible-playbook delegate_to错误

时间:2015-10-23 15:00:10

标签: ansible ansible-playbook

我有一本剧本,这是其中的一部分。

...

- name: Wait for SSH to start
  wait_for:
    host: "{{ newmachines.instances[0].public_ip }}"
    port: 22
    timeout: 300
  delegate_to: localhost

... ansible-playbook --check create_instance.yml.old 错误:delegate_to不是Ansible Play的合法参数

ansible-playbook --version ansible-playbook 1.9.4   已配置的模块搜索路径=无

我该如何解决?

3 个答案:

答案 0 :(得分:3)

也许你应该检查你的缩进(标签/空格)? Ansible似乎认为delegate_to在游戏关卡中,而它是在您发布的代码外观的任务级别上。

这不起作用:

---
- hosts: myhost
  gather_facts: false
  tasks:
  - name: Wait for SSH to start
    wait_for:
      host: myhost
      port: 22
      timeout: 300
  delegate_to: localhost

它因你提到的错误而失败:

$ ansible-playbook -i hosts pb.yaml
ERROR! 'delegate_to' is not a valid attribute for a Play

虽然这样做(注意缩进差异):

---
- hosts: myhost
  gather_facts: false
  tasks:
  - name: Wait for SSH to start
    wait_for:
      host: myhost
      port: 22
      timeout: 300
    delegate_to: localhost

输出:

$ ansible-playbook -i hosts pb.yaml

PLAY [myhost] ****************************************************************

TASK [Wait for SSH to start] ***************************************************
ok: [myhost-> localhost]

PLAY RECAP *********************************************************************
myhost: ok=1    changed=0    unreachable=0    failed=0

答案 1 :(得分:1)

@serko该剧本适用于ansible-playbook 1.9.4

---
# main.yml
- hosts: all
  gather_facts: false
  tasks:
    - name: Wait for SSH to start
      wait_for:
        host: "localhost"
        port: 22
        timeout: 300
      delegate_to: localhost

$ ansible-playbook --check main.yml

PLAY [all] ********************************************************************

TASK: [Wait for SSH to start] *************************************************
skipping: [127.0.0.1 -> localhost]
ok: [127.0.0.1 -> localhost]

PLAY RECAP ********************************************************************
127.0.0.1                  : ok=0    changed=0    unreachable=0    failed=0

答案 2 :(得分:-3)

任务的参数格式应为key=value,而不是key:value。这让Ansible感到困惑。你想要的是这个:

- name: Wait for SSH to start
  wait_for:
    host="{{ newmachines.instances[0].public_ip }}"
    port=22
    timeout=300
  delegate_to: localhost

任务的修饰符(例如delegate_towith_items等)应使用: