本文介绍了为什么 Ansible 跳过主机组并且什么都不做的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试运行我的 Ansible 时遇到问题.这是我的主机文件:

trying to run my Ansible and have a problem.here is my hosts file:

[dse]
node1 192.168.56.10
node2 192.168.56.20
node3 192.168.56.30

[opscenter]
opscenter 192.168.56.40

[sparkmasters]
node3 192.168.56.30

[sparkworkers]
node1 192.168.56.10
node2 192.168.56.20
node3 192.168.56.30

这是我的 yml 的一部分:

Here is a part of my yml:

---
- hosts: [ "node1", "node2", "node3", "node4" ]
  user: vagrant
  sudo: True
  vars:
      username: spark
  tasks:
    - include: some tasks


  roles:
    - some roles


- hosts: sparkmasters
  vars:
    spark.version: 1.2
  roles:
    - spark_master

- hosts: sparkworkers
  vars:
    spark.version: 1.2
  roles:
    - spark_workers

我看到 [ "node1", "node2", "node3", "node4" ] 运行,但 hosts: sparkmasters 和 hosts: sparkworkers 被跳过,消息如下:

I see that [ "node1", "node2", "node3", "node4" ] runs, but hosts: sparkmasters and hosts: sparkworkers are skipped with the message:

PLAY [火花大师]*************************************************************** 跳过:没有主机匹配

PLAY [火花工作者]*************************************************************** 跳过:没有主机匹配

PLAY [sparkworkers] *********************************************************** skipping: no hosts matched

播放回顾************************************************************************ 节点 1:ok=21 已更改=12 无法访问=0
失败=0

PLAY RECAP ******************************************************************** node1 : ok=21 changed=12 unreachable=0
failed=0

==> node1:运行供应商:ansible...

==> node1: Running provisioner: ansible...

不知道为什么.如果我将组名更改为主机数组,则它开始工作...

Don't have any idea why. If i change group name to array of hosts, then it start to work...

我做错了什么?

所以我添加了调试:

- name: Display hostvars
  debug: var=hostvars

看看这个:

"hostvars": {
        "node1": {
            "ansible_all_ipv4_addresses": [
                "10.0.2.15",
                "192.168.56.10"
            ],

这个巨大的 json 包含更多与我的主机相关的元数据我不明白,我应该在那里看到什么?我没有找到任何与当前主机组信息相关的信息

and this huge json has much more metadata related to my hostI didn't get idea, what should I see there? I didn't find any info related to current host group info

推荐答案

这是 ansible+vagrant 特色:https://serverfault.com/questions/585722/ansible-not-executing-host-specific-playbook-in-vagrant-multi-machine-provisioni

It's ansible+vagrant specialities: https://serverfault.com/questions/585722/ansible-not-executing-host-specific-playbook-in-vagrant-multi-machine-provisioni

所以我在 Vagrant 文件中添加了 gropus 声明并且它开始工作了:

So I've added gropus declaration to Vagrant file and it started to work:

config.vm.provision "ansible" do |ansible|
    ansible.playbook = "deploy.yml"
    ansible.groups = {
        "dse" => ["dsenode01","dsenode02","dsenode03"],
        "opscenter" => ["dsenode03"],
        "sparkmasters" => ["dsenode01"],
        "sparkworkers" => ["dsenode01","dsenode02","dsenode03"]
    }
  end

这篇关于为什么 Ansible 跳过主机组并且什么都不做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 20:25