2016-10-03 105 views
0

我有一个具有从git的作用结账代码(以下两个拷贝)一个test.yml文件:ansible角色无法找到模块

site.yml

--- 
- hosts: webservers 
    user: me 
    roles: 
    - role: test-role 

为主。在测试角色YML文件/任务

--- 

- name: fetching my repo 
    vars: 
    my_repo_url: [email protected]:myrepo/my-server.git 
    my_proj_path: /tmp/repos/my-server/ 
    tasks: 
    - name: check out git repository on host 
    git: repo={{ my_repo_url }} dest={{ my_proj_path }} accept_hostkey=yes 

主机:

[webservers] 
testserver ansible_ssh_host=xxx.xxx.xxx.xxxx ansible_ssh_port=xxxx 
当我运行以下

ansible-playbook -i hosts site.yml 

我得到复制下面引用了角色的任务部分的main.yml文件除外。任何想法我可能错误配置。

ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path. 

The error appears to have been in '/home/user/git/roles/test-role/tasks/main.yml': line 3, column 3, but may 
be elsewhere in the file depending on the exact syntax problem. 

The offending line appears to be: 


- name: fetching my repo 
^here 


The error appears to have been in '/home/user/git/test/roles/test-role/tasks/main.yml': line 3, column 3, but may 
be elsewhere in the file depending on the exact syntax problem. 

The offending line appears to be: 


- name: fetching my repo 
^here 

更新 试图改变按康斯坦丁的反馈,但我得到或多或少相同的异常:

角色/测试角色/默认/ main.yml

--- 
    vars: 
    my_repo_url: [email protected]:myrepo/my-server.git 
    my_proj_path: /tmp/repos/my-server/ 

tasks/main.yml

--- 
- name: fetching my repo 
    tasks: 
    - name: check out git repository on host 
    git: repo={{ my_repo_url }} dest={{ my_proj_path }} accept_hostkey=yes 

例外: 现在它抱怨下面的行。当我运行语法检查时,我得到相同的响应。

--- 
- name: fetching my repo 
^here 

更新 其次康斯坦丁和Avalon的答案 - 我能成功运行任务。

回答

1

main.yml对于角色应该只包含任务列表,没有别的。

分割你的文件转换成test-role/defaults/main.yml(变量):

--- 
my_repo_url: [email protected]:myrepo/my-server.git 
my_proj_path: /tmp/repos/my-server/ 

test-role/tasks/main.yml(任务):

--- 
# fetching my repo 
- name: check out git repository on host 
    git: repo={{ my_repo_url }} dest={{ my_proj_path }} accept_hostkey=yes 
+0

spaciba - 更新我的原始文章与您的建议,但它不工作 - 任何想法 - 在此先感谢 –

+0

我的代码是不同的,请密切关注,请。 –

+0

spaciba - 两个答案同样有用 –

1

要添加到什么康斯坦丁说,你的任务应该只包含任务。变量需要在单独的文件中定义。此外,你的语法/格式可以改进。

site.yml

--- 
- hosts: webservers 
    user: me 
    roles: 
    - test-role 

角色/测试角色/任务/主。阳明海运

--- 
- name: fetching my repo 
    git: repo={{ my_repo_url }} dest={{ my_proj_path }} accept_hostkey=yes 

角色/测试角色/瓦尔/ main.yml

--- 
my_repo_url: [email protected]:myrepo/my-server.git 
my_proj_path: /tmp/repos/my-server/ 

另外,我建议设置你的ansible.cfg文件库存路径。配置文件可以在/etc/ansible.cfg中,也可以在与您的剧本相同的目录中(我个人将它放在与我的剧本相同的目录中)。

ansible.cfg

inventory  = inventory/hosts 

如果你这样做,你会不会当你运行你的剧本到指定目录文件的位置。如果没有别的,它会为您节省几个按键。

您应该查看this URL了解创建角色结构的最佳实践和示例。

+0

谢谢 - 将尝试 –

+0

谢谢 - 作品像一个魅力。自从它进来后,我接受了康斯坦丁的回答(两者都是upvoted)。 –