当前位置:网站首页>ansible-cmdb friendly display ansible collects host information

ansible-cmdb friendly display ansible collects host information

2022-08-09 13:15:00 51CTO

一、概述

Ansible-cmdb 获取 Ansible The output of fact collection and convert it to static containing system configuration information HTML 概览页面(和其他内容).

It supports multiple types of output(html、csv、sql 等)and extended with custom data Ansible 收集的信息.for each host,It also shows groups、主机变量、Custom variables and machine-local facts.

二、操作

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、Generated for all hostsfacts信息
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--templateparameter to choose your template
'html_fancy' Template is the default

Ansible-cmdb The following templates are currently available out of the box:
html_fancy:Dynamic modern with all hosts HTML 页面.
html_fancy_split:A dynamic modern HTML 页面,Details for each host are in a separate file.
txt_table:A quick text table summary of available hosts,Contains some minimal information.
json:以 JSON format dumps all hosts,包括组、变量、自定义信息.
csv:CSV Template output for your host CSV 文件.
markdown:Markdown 模板生成 Markdown Format host information.
sql:SQL 模板会生成一个 .sql 文件,该文件可以加载到 SQLite 或 MySQL 数据库中.

html_fancy_split:该模板与html_fancyThe templates are basically the same,But it generates onecmdb/目录,其中包含一个index.html文件和一个单独的 html 文件,
Used to record the details of each host.If you have a lot of hosts and html_fancy Template rendering is too slow,这将非常有用.
用法:
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,support column.If the template supports columns,您可以使用--columns/-cCommand line options to specify the columns to display.
Requires a comma-separated one--columns列列表(没有空格!),应该显示.Columns must be defined by theirid字段指定.有关idInformation on which fields the template supports,Please see the template.
Usually it is the column header,But use lowercase letters and replace spaces with underscores.
ansible-cmdb -t txt_table --columns name,os,ip,mem,cpus facts/

您可以使用该--exclude-colsoption to exclude specific columns.它的工作原理与--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://yzsam.com/2022/221/202208091152355036.html