2015-10-23 67 views
0

我有一個劇本,這是它的一部分。Ansible:ansible-playbook delegate_to error

...

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

... ansible - 劇本 - 檢查create_instance.yml.old ERROR:delegate_to不是Ansible的播放

ansible-劇本合法參數 - -version ansible-playbook 1.9.4 已配置模塊搜索路徑=無

我該如何解決?

回答

-2

該任務的參數應採用格式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等應使用:

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

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