也許你應該檢查你的縮進(製表符/空格)? 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