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

查看:28
本文介绍了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 : 获取 dbnodes IP 地址] ********************************致命:[162.220.52.190]:失败!=> {"failed": true, "msg": "the field 'action' has an invalid value, 它似乎包含一个未定义的变量.错误是:'dict object' has no attribute 'ansible_eth0'\n\n错误似乎在 '/root/tenon-delivery/ansible/roles/dbcluster/tasks/main.yml':第 52 行,第 3 列,但可能\n在文件中的其他地方,具体取决于确切的语法问题.\n\n违规行似乎是:\n\n\n- name: getting dbnodes IP address\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天全站免登陆