2017-07-03 52 views
0

我正在關注此頁面Clone a private git repository with Ansible (using password prompt)以解決我的需求。重複使用相同的模板在我的劇本main.yml,其內容爲將Git憑據傳遞給Ansible拋出錯誤

--- 
- name: move CentOS repo definitions outside temp 
    copy: 
    src: "{{ item }}" 
    dest: /etc/yum.repos.d/ 
    owner: "root" 
    mode: 0600 
    with_fileglob: 
    - /etc/yum.repos.d/temp/* 
    become: true 

- name: passing git credentials for cloning the repos 
    vars_prompt: 
    - name: "githubuser" 
     prompt: "Enter your github username" 
     private: no 
    - name: "githubpassword" 
     prompt: "Enter your github password" 
     private: yes 

和一些更多的下面。現在面臨一個錯誤

The error appears to have been in '/tmp/.../tasks/main.yml': line 12, column 3, but may 
be elsewhere in the file depending on the exact syntax problem. 

The offending line appears to be: 


- name: passing git credentials for cloning the repos 
^here 


The error appears to have been in '/tmp/.../tasks/main.yml': line 12, column 3, but may 
be elsewhere in the file depending on the exact syntax problem. 

The offending line appears to be: 


- name: passing git credentials for cloning the repos 
^here 

我使用可用

ansible-playbook main.yml --syntax-check 

,並在YAML lint語法檢查選項驗證了yml,但似乎無法找到原因被認爲是錯誤的原因。

回答

1

不能在任務級別使用vars_prompt,只能在劇本級別使用。

如果您的main.yml是角色的一部分,您應該將提示塊移至包含角色的上層劇本。

+0

偉大的觀察!正在檢查我是否可以將其移至上一層。除了使用'vars_prompt'之外,還有另外一種方法來實現這個嗎? – Inian

+3

Ansible首先是**自動化工具**。因此儘可能避免交互式活動,使用extra-vars,環境變量將其他數據傳遞到您的劇本中。 –

+0

感謝您的領導。完全刪除了該方法,決定使用包含憑據的加密var文件。謝謝 – Inian

相關問題