当gather_facts 为false 时,如何在调用ansible 角色之前显式运行安装模块? [英] How can I explicitely run the setup module before calling ansible roles when gather_facts is false?

查看:23
本文介绍了当gather_facts 为false 时,如何在调用ansible 角色之前显式运行安装模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 gather_facts 设置为 false,然后使用 setup 模块收集事实并在之后运行角色.

I want to set gather_facts to false but then use the setup module to gather facts and run the roles afterwards.

我的代码如下:

---
- name: RDS check
  hosts: "{{ run_on_node|default('cdh[0]')}}"
  gather_facts: False

  setup: #not sure about the indentation, but want to execute that before roles.
  roles:
    - { role: r1, when: "'10.200.1.197' in inventory_hostname" }

推荐答案

setup 模块必须在任务部分中执行.pre_tasksroles 之前执行.

setup module has to be executed in a task section. pre_tasks are executed before roles.

尝试如下:

---
- name: RDS check
  hosts: "{{ run_on_node|default('cdh[0]')}}"
  gather_facts: False
 
  pre_tasks:
  - name: Gather facts
    setup: 

  roles:
    - { role: r1, when: "'10.200.1.197' in inventory_hostname" }

这篇关于当gather_facts 为false 时,如何在调用ansible 角色之前显式运行安装模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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