Ansible循环相关问题 [英] Ansible loop related issues

查看:234
本文介绍了Ansible循环相关问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一本剧本,它具有多个角色和串行设置,因此它首先在一台计算机上运行,​​然后在其余计算机上运行.在其中一个角色中,我具有以下任务:

I have a playbook which has multiple roles and serial setup so that fist it's running on one machine then on the rest of them. In one of the roles I have the following tasks:

- name: getting dbnodes IP addresses
  local_action: shell echo  "{% for host in groups['dbnodes'] %}{{ hostvars[host]['ansible_eth0']['ipv4']['address'] }},{% endfor %}"
  run_once: true
  register: IPS

基本上,我要做的是收集所有主机的IP地址,并将其注册到IPS中以备将来使用.但是由于串行错误(我认为)并出现以下错误,因此该任务失败了.

Basically what I want to do is to gather the IP addresses of all the hosts and register it with IPS for further usage. But the task is failing because of the serial (I think) with the following error.

TASK [dbcluster : getting dbnodes IP addresses] ******************************** fatal: [162.220.52.190]: FAILED! => {"failed": true, "msg": "the field 'action' has an invalid value, which appears to include a variable that is undefined. The error was: 'dict object' has no attribute 'ansible_eth0'\n\nThe error appears to have been in '/root/tenon-delivery/ansible/roles/dbcluster/tasks/main.yml': line 52, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: getting dbnodes IP addresses\n ^ here\n"}

TASK [dbcluster : getting dbnodes IP addresses] ******************************** fatal: [162.220.52.190]: FAILED! => {"failed": true, "msg": "the field 'action' has an invalid value, which appears to include a variable that is undefined. The error was: 'dict object' has no attribute 'ansible_eth0'\n\nThe error appears to have been in '/root/tenon-delivery/ansible/roles/dbcluster/tasks/main.yml': line 52, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: getting dbnodes IP addresses\n ^ here\n"}

运行ansible dbnode -s setup时,我可以看到ansible_eth0具有适当的值.我不明白为什么要说它是未定义的.

While running ansible dbnode -s setup I can see that the ansible_eth0 has a proper value. I don't understand why it is saying that it's undefined.

任何想法如何在同一时间在所有计算机上收集事实,同时仍然可以选择将多个任务/处理程序序列化.

Any idea how to gather the facts on all machines in the same time while still having the option several tasks/handlers still being done serialized.

推荐答案

ansible_eth0在任务运行时事实可能是未知的.

ansible_eth0 fact may be unknown at the time of your task run.

您可能想在剧本的最顶部添加事实收集剧本:

You may want to add fact gathering play at the very top of your playbook:

- hosts: dbnodes
  gather_facts: yes
  tasks:
    - debug: msg="facts gathering"

- hosts: othernodes
  tasks:
    - name: getting dbnodes IP addresses
      ...

这篇关于Ansible循环相关问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆