2017-02-08 51 views
0

與我有以下劇本example.yml:Ansible劇本當變量不執行

- hosts: all 
    remote_user: administrator 
    become: yes 
    tasks: 
    - name: Put resolv.conf 
    template: 
     src: /home/user/resolv.conf.j2 
     dest: /etc/resolv.conf 
     backup: yes 
     mode: 0644 
     when: variable_name == "string" 

的目的是通過一個定製的一個更新的resolv.conf。

爲了執行它,我跑:

ansible-playbook example.yml -k -u administrator --become --ask-become-pass --limit server_name -e variable_name='string' 

不過,我得到以下錯誤:

SSH password: 
SUDO password[defaults to SSH password]: 

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

TASK [setup] ******************************************************************* 
ok: [server_name] 

TASK [Put resolv.conf] ******************************************************* 
fatal: [server_name]: FAILED! => {"changed": true, "failed": true, "msg": "unsupported parameter for module: when"} 
    to retry, use: --limit @/home/user/playbooks/example.retry 

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

我已經通過應用不同的語法嘗試「()」的變量,之間的變化雙倍和單一逗號等,但始終是相同的錯誤。

如果我不使用both,variable和when條件,則任務會成功完成。

問題在哪裏?

回答

3

注意填充!

- hosts: all 
    remote_user: administrator 
    become: yes 
    tasks: 
    - name: Put resolv.conf 
    template: 
     src: /home/user/resolv.conf.j2 
     dest: /etc/resolv.conf 
     backup: yes 
     mode: 0644 
    when: variable_name == "string" 

when是一個任務屬性,而不是template的參數。