为什么Ansible会跳过主机组而不执行任何操作

时间:2015-04-04 20:03:58

标签: apache-spark ansible

尝试运行我的Ansible并遇到问题。 这是我的主持人文件:

[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的一部分:

---
- 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"运行,但主机:sparkmasters和主机:sparkworkers被跳过消息:

  

播放[sparkmasters]   ************************************************** *********跳过:没有匹配的主机

     

播放[sparkworkers]   ************************************************** *********跳过:没有匹配的主机

     

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

     

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

不知道为什么。如果我将组名更改为主机阵列,那么它开始工作......

我做错了什么?

所以我添加了调试:

- name: Display hostvars
  debug: var=hostvars

看到这个:

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

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

1 个答案:

答案 0 :(得分:2)

它的ansible + vagrant special:https://serverfault.com/questions/585722/ansible-not-executing-host-specific-playbook-in-vagrant-multi-machine-provisioni

所以我已经向Vagrant文​​件添加了gropus声明,它开始起作用了:

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