【问题标题】:ansible \ any reason why .yml role element don't run roles/x/tasks/main.ymlansible \ .yml 角色元素不运行角色/x/tasks/main.yml 的任何原因
【发布时间】:2016-06-20 19:54:53
【问题描述】:

我做的和所有教程一模一样,没有拼写错误,甚至可以单独运行 /roles/x 中的 main.yml

但是当我运行应该调用它的剧本时 - 什么都没有发生

父母

---
- name: Install / Upgrade tagger
  hosts: tagger
  roles:
    - tagger

/roles/tagger/tasks/main.yml

---
- command: echo 1

需要说我在 localhost 中运行所有内容。 也试过了

 ansible-playbook -i "localhost" -c local tagger.yml 

ansible-playbook -i "localhost" -c local tagger.yml

 [WARNING]: Host file not found: localhost

 [WARNING]: provided hosts list is empty, only localhost is available


PLAY [build tagger docker] *****************************************************

TASK [setup] *******************************************************************
ok: [localhost]

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

【问题讨论】:

  • 您的角色名称是x 还是taggermain.yml 的路径应该是 roles/tagger/tasks/main.yml
  • tagger :) 这太奇怪了...
  • 你确定你调用了正确的剧本文件吗?您显示了一个名为“Install / Upgrade tagger”的文件,但您的输出显示了“build tagger docker”。
  • 无关问题:在 ansible 调用中 localhost 后添加逗号:-i "localhost,"。 Ansible 正在寻找一个名为“localhost”的文件。通过添加逗号,它将输入解释为主机名列表。
  • 谢谢(现在没有警告)-问题仍然存在

标签: ansible ansible-playbook


【解决方案1】:

使用您提供的命令行:

$ ansible-playbook -i "localhost" -c local tagger.yml 
ERROR: Unable to find an inventory file, specify one with -i ?

明显更正(加逗号):

$ ansible-playbook -i "localhost," -c local tagger.yml 

PLAY [Install / Upgrade tagger] *********************************************** 
skipping: no hosts matched

PLAY RECAP ******************************************************************** 

这仍然与您的输出不匹配,但它确实表明了问题。 localhost 永远不是 tagger。也许您正在使用hosts.ini 文件而不告诉我们它?还是与我的不同的特定版本的ansible?无论如何,我将hosts: tagger更改为hosts: all如下:

---
- name: Install / Upgrade tagger
  hosts: all
  roles:
    - tagger

然后我重新运行:

$ ansible-playbook -i "localhost," -c local tagger.yml

PLAY [Install / Upgrade tagger] *********************************************** 

GATHERING FACTS *************************************************************** 
ok: [localhost]

TASK: [tagger | command echo 1] *********************************************** 
changed: [localhost]

PLAY RECAP ******************************************************************** 
localhost                  : ok=2    changed=1    unreachable=0    failed=0   

所以有两个必要的修复。

【讨论】:

  • wierd ...做了两个更改,仍然忽略了角色..(我有ansible 2.1.0.0)。我不使用任何 hosts.ini 文件 - 也许我会尝试一下
  • 在另一台机器上也是 2.1 @user1025852?
猜你喜欢
  • 2017-02-21
  • 1970-01-01
  • 2018-05-14
  • 2021-04-05
  • 1970-01-01
  • 1970-01-01
  • 2015-08-26
  • 1970-01-01
相关资源
最近更新 更多