如何列出主机所属的组? [英] How to list groups that host is member of?

查看:26
本文介绍了如何列出主机所属的组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常复杂的 Ansible 设置,其中包含数千台服务器和数百个组,各种服务器是其成员(动态清单文件).

I have a very complex Ansible setup with thousands of servers and hundreds of groups various servers are member of (dynamic inventory file).

有什么方法可以轻松显示特定主机所属的所有组?

Is there any way to easily display all groups that a specific host is member of?

我知道如何列出所有群组及其成员:

I know how to list all groups and their members:

ansible localhost -m debug -a 'var=groups'

但我不想为所有主机执行此操作,而只想为单个主机执行此操作.

But I want to do this not for ALL hosts, but only for a single one.

推荐答案

创建一个名为showgroups"(可执行文件)的剧本,其中包含:

Create a playbook called 'showgroups' (executable file) containing:

#!/usr/bin/env ansible-playbook

- hosts: all
  gather_facts: no
  tasks:
  - name: show the groups the host(s) are in
    debug:
      msg: "{{group_names}}"

您可以像这样运行它以显示清单 (-i) 中某个特定主机 (-l) 的组:

You can run it like this to show the groups of one particular host (-l) in your inventory (-i):

 ./showgroups -i develop -l jessie.fritz.box 

这篇关于如何列出主机所属的组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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