2016-10-29 39 views
0

我有一本完美的劇本。當我運行劇本時,我指定要使用哪個環境文件。在劇本中包含劇本並定義環境文件

ansible-playbook playbooks/release-deploy.yaml -i env/LAB3 

在劇本中,我打電話給另一個劇本,我想要使用相同的環境文件。

我現在的配置是:

- include: tasks/replace_configs.yaml 

所以,當我跑了劇本,我得到的錯誤:

TASK [include] ***************************************************************** 
fatal: [10.169.99.70]: FAILED! => {"failed": true, "reason": "no action detected in task. This often indicates a misspelled module name, or incorrect module path. 

The error appears to have been in '/home/ansible/playbooks/tasks/replace_configs.yaml': line 2, column 3, but may 
be elsewhere in the file depending on the exact syntax problem. 

The offending line appears to be: 

--- 
- hosts: cac 
^here 


The error appears to have been in '/home/ansible/playbooks/tasks/replace_configs.yaml': line 2, column 3, but may 
be elsewhere in the file depending on the exact syntax problem. 


The offending line appears to be: 

--- 
- hosts: cac 
^here 
"} 

tasks/replace_configs.yaml還需要使用env/LAB3

看起來它不」不知道什麼cac是。我需要做另一個配置嗎?

+0

分享您的包含文件以及env文件 – Shasha99

回答

2

My current config is:

- include: tasks/replace_configs.yaml 

這不是任何「配置」,這是一個系列,其包括含有任務的文件。

讓我們來看看下面的「任務」:

The offending line appears to be: 

--- 
- hosts: cac 
^here 

它看起來並不像一個任務,它看起來像一個發揮。它最有可能不包含任何模塊指令,因此Ansible正確地抱怨說,在預期的任務中沒有提供模塊名稱:no action detected in task

當您在Ansible使用include指令,它把包含的內容在include的縮進級別,所以當你有任務,你應該包括任務

你的包含文件應該是這樣:

--- 
- name: This is a task 
    debug: msg="One task" 

- name: This is another task 
    debug: msg="Another task" 

並且不應該包含任何其他定義,特別是那些屬於更高級別的定義。

+0

感謝您的詳細解答。一旦我刪除了 - hosts行,它就可以很好地工作。 –