当前位置:网站首页>ansible-cmdb友好展示ansible收集主机信息

ansible-cmdb友好展示ansible收集主机信息

2022-08-09 12:02:00 51CTO

一、概述

Ansible-cmdb 获取 Ansible 事实收集的输出并将其转换为包含系统配置信息的静态 HTML 概览页面(和其他内容)。

它支持多种类型的输出(html、csv、sql 等)并使用自定义数据扩展 Ansible 收集的信息。对于每个主机,它还显示组、主机变量、自定义变量和机器本地事实。

二、操作

1、安装

      
      
1、pip安装
pip install ansible-cmdb
或者
pip install --upgrade ansible-cmdb

2、下载安装包
https://github.com/fboender/ansible-cmdb/
wget https://github.com/fboender/ansible-cmdb/releases/download/1.17/ansible-cmdb-1.17.tar.gz
tar -vxzf ansible-cmdb*.tar.gz
cd ansible-cmdb*
sudo make install

3、git直接拉取
git clone https://github.com/fboender/ansible-cmdb.git
cd ansible-cmdb
sudo bash -c ". build.sla && install"
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.

2、命令参数

      
      
Usage: ansible-cmdb [option] <dir> > output.html
Options:
--version show program 's version number and exit
-h, --help show this help message and exit
-t TEMPLATE, --template=TEMPLATE
Template to use. Default is 'html_fancy '
-i INVENTORY, --inventory=INVENTORY
Inventory to read extra info from
-f, --fact-cache <dir> contains fact-cache files
-p PARAMS, --params=PARAMS
Params to send to template
-d, --debug Show debug output
-q, --quiet Don't report warnings
-c COLUMNS, --columns =COLUMNS
Show only given columns
-C CUST_COLS, --cust -cols =CUST_COLS
Path to a custom columns definition file
-l LIMIT, --limit =LIMIT
Limit hosts to pattern
--exclude -cols =EXCLUDE_COLUMNS
Exclude cols from output
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.

3、使用

      
      
1、生成所有主机的facts信息
mkdir out
ansible -m setup --tree out/ all

2、使用ansible-cmdb生成html页面
ansible-cmdb out/ > overview.html
输出指定行
ansible-cmdb -c name,groups,vcpus,mem_usage,disk_usage out/ > overview.html
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.

ansible-cmdb友好展示ansible收集主机信息_sql

4、模板

      
      
ansible-cmdb 提供多个模板。-t您可以使用or--template参数选择您的模板
'html_fancy' 模板是默认的

Ansible-cmdb 目前提供以下开箱即用的模板:
html_fancy:包含所有主机的动态现代 HTML 页面。
html_fancy_split:一个动态的现代 HTML 页面,每个主机的详细信息都在一个单独的文件中。
txt_table:可用主机的快速文本表摘要,包含一些最少的信息。
json:以 JSON 格式转储所有主机,包括组、变量、自定义信息。
csv:CSV 模板输出您的主机的 CSV 文件。
markdown:Markdown 模板生成 Markdown 格式的主机信息。
sql:SQL 模板会生成一个 .sql 文件,该文件可以加载到 SQLite 或 MySQL 数据库中。

html_fancy_split:该模板与html_fancy模板基本相同,但它会生成一个cmdb/目录,其中包含一个index.html文件和一个单独的 html 文件,
用于记录每个主机的详细信息。如果您有大量主机并且 html_fancy 模板呈现速度太慢,这将非常有用。
用法:
ansible-cmdb -t html_fancy_split -i hosts out/

sql:该sql模板会生成一个 .sql 文件,该文件可以加载到 SQLite 或 MySQL 数据库中。
$ ansible -cmdb -t sql -i hosts out > cmdb.sql
$ echo "CREATE DATABASE ansiblecmdb" | mysql
$ mysql ansiblecmdb < cmdb.sql
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.

5、指定列

      
      
一些模板,例如 txt_table 和 html_fancy,支持列。如果模板支持列,您可以使用--columns/-c命令行选项来指定要显示的列。
需要一个逗号分隔的--columns列列表(没有空格!),应该显示。列必须由它们的id字段指定。有关id模板支持哪些字段的信息,请查看模板。
通常它是列标题,但使用小写字母并用下划线替换空格。
ansible-cmdb -t txt_table --columns name,os,ip,mem,cpus facts/

您可以使用该--exclude-cols选项排除特定列。它的工作原理与--columns. 例如
ansible-cmdb -t html_fancy_split \
--exclude -cols mem_usage,swap_usage,disk_usage,physdisk_size \
-i hosts \
facts/
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.

6、具体详细介绍

可以参考github

 ​https://github.com/fboender/ansible-cmdb/blob/master/docs/usage.md​

原网站

版权声明
本文为[51CTO]所创,转载请带上原文链接,感谢
https://blog.51cto.com/u_13236892/5557258