找回密码
 注册
查看: 559|回复: 3

ansible-cmdb使用方法 安装流程

[复制链接]

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
发表于 2023-3-27 15:00:01 | 显示全部楼层 |阅读模式

Running from github source:

$ cd ansible-cmdb
7 E4 w4 u) @; E$ r7 c: M  E6 p$ export PYTHONPATH=lib
4 t/ W4 A) `/ I+ D; `$ src/ansible-cmdb examples/out > ~/cmdb.html# I" r) b2 w( R' N: Y# v9 o
' K3 R/ f1 B& _) e- y2 j: O) E* E
$ src/ansible-cmdb -i examples/hosts examples/out > ~/cmdb.html; o* \6 J$ x2 {4 j) N
! v+ D( X8 Z* ^# d
$ src/ansible-cmdb -p local_js=1 -i examples/hosts examples/out > ~/cmdb.html
4 o6 f; p- |7 K; R; `
) B, M( L3 H7 g% H
4 f$ I% X' c+ Y. U2 Q

Installing from github source:

$ cd ansible-cmdb$ sudo python ./setup.py install$ ansible-cmdb ansible-cmdb/examples/out > ~/cmdb.html$ ansible-cmdb -i ansible-cmdb/examples/hosts ansible-cmdb/examples/out > ~/cmdb.html$ ansible-cmdb -p local_js=1 -i ansible-cmdb/examples/hosts ansible-cmdb/examples/out > ~/cmdb.html$ sudo pip uninstall mako$ sudo pip uninstall pyyaml$ sudo pip uninstall ansible-cmdb$ sudo rm /usr/local/bin/ansible-cmdb

Installing from source tarbal:

$ tar -vxzf ansible-cmdb-*.tar.gz. v! l1 i$ \% {# |1 e' [

" v7 b: _2 K/ e  ?& G0 J$ cd ansible-cmdb-*5 b9 g4 z2 ?2 T5 g
& u* S6 g: u8 e- X3 j; E8 g- h
$ sudo make install% }6 n3 ~& o' \
4 Y' w" U, X* I; }
$ ansible-cmdb out > ~/cmdb.html
3 m+ ?7 O! N9 z$ M; a9 }! g: l- H# ^( Q* C3 i' P$ f, U
$ ansible-cmdb -i hosts out > ~/cmdb.html, ?5 @) R+ K2 {5 M8 _0 j5 {1 h1 a

& m, D& B$ W4 }4 i2 }& ~+ r$ ansible-cmdb -p local_js=1 -i hosts out > ~/cmdb.html5 {6 G# M5 j. b+ i1 A
1 p" ]. d# |+ X3 c% s* o
$ cd ansible-cmdb-*& U% R- `: V4 s, h

1 }; m  _/ }6 h% I2 M7 V$ sudo make uninstall
+ L: F7 k/ V# |6 O! U; E7 n4 b

. v$ }, ^: f/ P6 i9 Z

Installing from .deb file:

3 `; k2 ^. X8 r" E

$ dpkg -i -i ansible-cmdb-*.deb8 y6 Z1 L0 o  [; {6 [
) K% M7 C6 X- U" J! T. h% [* `
$ ansible-cmdb out > ~/cmdb.html' s8 m+ u2 W6 A! x2 G! j

+ e; J3 K! `# _: c1 v$ ansible-cmdb -i hosts out > ~/cmdb.html
% e& ]4 `2 o5 S* x; l7 K9 Q0 i1 V# v: A+ Z# ~5 _
$ ansible-cmdb -p local_js=1 -i hosts out > ~/cmdb.html5 B3 K4 \! J/ y8 ~" h
/ d, l3 p* `9 P) a$ d3 l
$ sudo dpkg --purge ansible-cmdb
+ M2 p! Y. x) d. t1 m) Z
- Y! r( A/ B6 I0 p( ~( B# u; z6 W& Q7 l/ L

Installing from .rpm file:

$ sudo yum install ansible-cmdb*.rpm
4 O5 F! J" ]+ A2 c
6 F3 p# C) r& k/ _; d3 N$ ansible-cmdb out > ~/cmdb.html
9 ?3 H6 @, C- l, K
/ j5 ]: I& m. n. ^7 S1 B/ y" H$ ansible-cmdb -i hosts out > ~/cmdb.html6 W$ x0 w5 e8 @3 p

5 T) q5 d7 j1 ~# a  B1 Y$ ansible-cmdb -p local_js=1 -i hosts out > ~/cmdb.html& P' \3 g  x# r" W
; a- ?7 m  u5 L0 O6 x
$ sudo yum uninstall ansible-cmdb2 ]% H6 T( S7 i& M  L

4 R- u8 B5 d2 V3 b9 JLicense

Ansible-cmdb is licensed under the GPLv3:

This program is free software: you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation, either version 3 of the License, or(at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program.  If not, see <http://www.gnu.org/licenses/>.For the full license, see the LICENSE file.
9 g4 k% f5 `2 P$ p5 I
: C" f0 u+ l, P& Q* K! y9 O. G
. A- a* o7 d( H" J; Z) e* t! Z
2 M+ O1 g2 \0 y4 }+ k  |1 M

5 m+ C. q( a  F
8 b' n$ U. H$ g' I! s
9 H# p' q0 v8 i! p  g1 j
* {$ Z4 r* Z9 _2 \" }: N! b; N2 N  N' W
/ e7 }% X9 s6 I% u" m" b$ r: l
+ o6 i$ y* y/ |: {: K; f2 P

7 o* b4 K# l/ \1 y# n( X! {1 [/ k5 ?2 y$ }
2 s% H4 G7 O5 @& L
Running from github source:
* S  I1 u4 i2 K( ]- T; i; r0 }& |8 O* o, U+ ?- B, T. T. g
$ cd ansible-cmdb6 C; d1 v% X/ O8 |2 A$ m0 S, f
$ export PYTHONPATH=lib5 E: _0 b$ e- W  U
$ src/ansible-cmdb examples/out > ~/cmdb.html
/ E2 m9 s. G5 n5 {$ src/ansible-cmdb -i examples/hosts examples/out > ~/cmdb.html# L/ E1 ~0 @& M  U& E/ h- M
$ src/ansible-cmdb -p local_js=1 -i examples/hosts examples/out > ~/cmdb.html9 u8 _/ a  W! H2 g* F, e3 d
Installing from github source:
2 B' [# y1 \2 t/ `8 J' W  o4 H6 ]2 J0 x: t& Q
$ cd ansible-cmdb2 V4 _$ I+ D) e6 t. h9 o
$ sudo python ./setup.py install" A6 [/ Z/ V3 W7 Y! T: r% G8 C
$ ansible-cmdb ansible-cmdb/examples/out > ~/cmdb.html
+ [9 _1 J( V& `% v* _7 R$ ansible-cmdb -i ansible-cmdb/examples/hosts ansible-cmdb/examples/out > ~/cmdb.html
  _0 S3 F' j& N4 ]( p$ ansible-cmdb -p local_js=1 -i ansible-cmdb/examples/hosts ansible-cmdb/examples/out > ~/cmdb.html/ y7 x9 j" k0 J" N/ {* {3 R9 x
$ sudo pip uninstall mako
: A) j  d) |; b$ C: F/ c6 |$ sudo pip uninstall pyyaml5 d: @$ H% ^8 Q
$ sudo pip uninstall ansible-cmdb) @- z% K; C7 a
$ sudo rm /usr/local/bin/ansible-cmdb
4 ^' F7 D# K7 D/ u+ w" CInstalling from source tarbal:
" w" k; e3 F2 H
5 \1 Z# B, v3 C# ]( B# }4 M$ tar -vxzf ansible-cmdb-*.tar.gz
* n- Z3 P2 X4 z$ cd ansible-cmdb-*
  U8 ~& [8 V7 m' |" a0 }" @9 \$ sudo make install
/ I8 X9 d9 x" L5 W% D# G! O$ ansible-cmdb out > ~/cmdb.html
, d. K) D; }$ M3 V$ ansible-cmdb -i hosts out > ~/cmdb.html2 S. v% F  [3 J, w" y
$ ansible-cmdb -p local_js=1 -i hosts out > ~/cmdb.html; l5 ^0 Z7 c& x, U1 |$ r( N
$ cd ansible-cmdb-*
! \& u# F8 |0 r9 F$ y$ sudo make uninstall
# I+ R6 q: J3 q1 [- t( KInstalling from .deb file:: c1 k) n$ J" i3 b
0 Q. ^5 I7 t4 _# x9 e! t
$ dpkg -i -i ansible-cmdb-*.deb
* q  ~0 Z# m; U6 ]6 l3 H  I$ ansible-cmdb out > ~/cmdb.html+ I: ^- T8 S* Q$ C) n8 \
$ ansible-cmdb -i hosts out > ~/cmdb.html# T2 Z6 a, w1 {( M1 a* v
$ ansible-cmdb -p local_js=1 -i hosts out > ~/cmdb.html
8 |. p: w% S% \% b; d$ sudo dpkg --purge ansible-cmdb: d: I. k# f; b+ c3 v. v
Installing from .rpm file:3 Y1 U! x2 [# i4 R
0 K7 _+ ^/ X) `# d+ O
$ sudo yum install ansible-cmdb*.rpm
3 V4 L# g  S0 B0 ~+ a$ ansible-cmdb out > ~/cmdb.html4 C+ u+ u& D4 g* t
$ ansible-cmdb -i hosts out > ~/cmdb.html
( p- C; m, x4 s. X/ H4 K: i, v$ ansible-cmdb -p local_js=1 -i hosts out > ~/cmdb.html3 }( j1 q; |3 f
$ sudo yum uninstall ansible-cmdb
6 `) g# e& S3 XLicense; X5 c+ P& S" U, C9 q
Ansible-cmdb is licensed under the GPLv3:! p- b; S+ K7 I! E7 n! |7 p0 U% x) G
' e( L- q# A4 M# V( U8 j: X
This program is free software: you can redistribute it and/or modify0 ^) Q" l1 ]9 l! h9 |# C
it under the terms of the GNU General Public License as published by" c9 k  K: p- Z6 X& V  i& w$ @2 D
the Free Software Foundation, either version 3 of the License, or
* \2 l) H9 K3 x7 `6 g- _(at your option) any later version.3 @, K' X1 M: [4 Y, A& q
: i+ D1 C$ C+ R* Y" [; o) i
This program is distributed in the hope that it will be useful,% \! J% R6 [4 g" d: D5 x$ H+ H( P
but WITHOUT ANY WARRANTY; without even the implied warranty of
$ D( x) ~. ?5 g- o" W6 JMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% e1 K" S5 i4 e( Z0 |GNU General Public License for more details.
+ |$ C+ b7 w. g0 ?9 X( V( O& l' @3 T  q7 a/ k) d$ t
You should have received a copy of the GNU General Public License
: l8 J) w0 y4 v1 B+ f- ualong with this program.  If not, see <http://www.gnu.org/licenses/>.
4 |4 d- O! ~7 m) I* o& i9 t, t  D
  s$ A3 }; G; `8 qFor the full license, see the LICENSE file.
" K3 ]( E1 I: \8 X: j1 t  G  A3 X1 y0 V9 g0 c+ ~: d, x
  |+ o5 [$ c$ I. T0 s0 z

! }7 l0 c8 w/ v- X! ~6 T7 x
) }5 `4 }& u5 H' l$ [
4 ~) C2 |4 J) c. ~6 @( p" ?

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2023-3-27 15:00:02 | 显示全部楼层
[root@jumpserver3 ~]# ansible -m setup --tree out/  -i inventory all% _; N& b$ a% I. z
使用ansible的setup模块收集数据生成文本文件,并存放到out目录下
/ W2 V2 h# R. b1 v; L9 T: g# p6 q; }" J+ S
ansible -i hosts -m setup --tree out/ all* Y: p5 x$ ]" B) s7 D% Q# K6 E
: T3 h: K+ }. ~' K2 e9 U- W
* h! e* l2 u2 u! b8 Q0 h
[root@jumpserver3 ~]# ansible-cmdb out/ > overview.html
' J8 U/ F" n$ a- i9 R, Q, D
% P& s: q$ w3 S* G- c! |[root@jumpserver3 ~]# ansible-cmdb -c name,groups,vcpus,mem_usage,disk_usage  out/  >overview-list.html 3 K7 E. d4 c/ l9 g/ L, \

" a: A! k, q( u# `5 J$ \5 d' Q+ e, X; l6 J8 h6 ^1 z* a! H% m
ansible-cmdb -t /usr/local/lib/ansible-cmdb/ansiblecmdb/data/tpl/csv.tpl  out/ > cmdb.csv

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2023-3-27 15:00:03 | 显示全部楼层
[root@jumpserver3 ~]# ansible -m setup -t html_fancy_split --tree  out/  -i inventory all

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2023-4-19 14:26:15 | 显示全部楼层
如果facts用了本地缓存,-f 指定缓存目录即可。
6 ~; D/ V) t' H  U* g2 j
5 @& A* i. R' y* ]% H! h/ ?
) O' b* z. ~8 V; o. E& k5 Vansible-cmdb -f /path/to/facts/dir > overview.html
7 D* |' z+ W, U6 z- E以资产列表得形式统计出ansible主机信息。. Z9 ?! }8 y* H( X
  k/ p9 h" V4 z
4 b$ W. I# i* g# t/ V
# ansible-cmdb -t txt_table --columns name,os,ip,mem,cpus out/
4 ]% K) ^! Y0 f3 ?4 nName       OS          IP              Mem  CPUs  
9 Y$ z1 [/ x( j9 \* w2 k---------  ----------  --------------  ---  ----  
9 ?4 E, t6 t) ?+ \0 Klocalhost  CentOS 7.6  192.168.77.130  1g   1  
% \+ z$ [+ j0 @* [( j输出csv格式的主机信息。
: P0 m/ p3 Z- w4 Q! S2 H+ R8 J; Z

4 i1 m" K8 e' a# u4 k# ansible-cmdb -t csv out/            
1 n& ]8 U9 Y: Q7 _6 R"Name","OS","IP","Arch","Mem","MemFree","MemUsed","CPUs","Virt","Disk avail": ]$ s6 ^0 ?& u0 b9 U* y
"localhost","CentOS 7.6","192.168.77.130","x86_64/x86_64","1g","0g","1g","1","VMware/guest","28.0g, 0.0g"8 J1 G* r0 H$ \
输出sql文件,导入数据到mysql或者SQLite。
* K+ H% O3 J2 ~8 C4 g
# ~) J- X9 ?8 O' l2 I- z! F% I* h+ ]
# ansible-cmdb -t sql out/
) _7 m( z( b2 Z% |$ f3 g6 J& gDROP TABLE IF EXISTS hosts;
! r9 m' I4 k- B& }# `' zCREATE TABLE hosts (6 b$ g# W, A$ R0 `
    name VARCHAR(255),
- q+ y0 I6 G7 A9 g+ J6 q8 v7 C( w    fqdn VARCHAR(255),) N2 b- X# G, _$ E
    main_ip VARCHAR(15),6 F+ w2 ~9 @# j, u( {* f1 L
    os_name VARCHAR(80),5 Q9 F/ ^2 K" v! V7 x6 `; w) M
    os_version VARCHAR(40),5 V$ i1 O+ }$ h9 K* G
    system VARCHAR(40)," d9 b) V' S8 Z/ I# ^
    kernel VARCHAR(40),- x) q3 u5 i! g7 z
    arch_hardware VARCHAR(12),
9 S: Q+ t, v! S* {" h    arch_userspace VARCHAR(12),
6 I3 n+ q' h' w" k    virt_type VARCHAR(20),' `1 y4 b$ X: I% |* ~
    virt_role VARCHAR(20),
6 k0 ~8 D3 [! [/ ?! g& x; L    cpu_type VARCHAR(60),# |& P9 y( G' G: {
    vcpus INT,
' W' \& M" v: U8 x, H. e; J    ram FLOAT,; {1 ^9 s9 f0 s1 Y' q0 V
    disk_total FLOAT,
& {( A. u8 }. m    disk_free FLOAT
# @- i/ T9 ?1 M6 d6 A  `);
" e) ~: l6 n' g" _& E0 m( |4 E3 P* a1 |( a' m) o4 O5 z# O/ [* X3 `- l
    INSERT INTO hosts (
' L( ?. y( w3 q% @        name,
$ R! M& B0 l% h2 ~# @( X% Z        fqdn,
7 Q' Q  [8 t* K' s4 q) G% p( P        main_ip,$ B# |$ g& c4 K  `
        os_name,
7 X, {6 i" x+ W. p9 J# ~8 \% `        os_version,( b  B! \7 S3 s1 H" ?+ p* M
        system,
: {6 Y1 P, \+ a# i        kernel,
) {( N) N1 e" I) L8 |0 k" j        arch_hardware,. o3 `$ o$ |* b8 c
        arch_userspace,
- D- B* E' k$ K+ {        virt_type,! {) u; V# U8 _; S# ]
        virt_role,# r. c1 j7 O( _& |/ N) i* B
        cpu_type,
5 @  \3 g% Y# D+ h3 ~4 i        vcpus,
8 V' n# R9 T# \# p* c0 @7 M. H        ram,
2 W) i6 \8 b3 }$ r* L8 x        disk_total,7 a8 t" C+ l  Z. t. j3 r1 }0 [
        disk_free2 N/ m0 ]3 n7 n$ ?  P
    ) VALUES (
% ^) W/ Y5 @; Z1 R8 |        "localhost",2 D5 y2 U, ]9 T2 M6 X% ~  f: G
        "a23-202-231-167.deploy.static.akamaitechnologies.com",
+ p; o% w* l' w7 m        "192.168.77.130"," T9 G# `" r. x
        "CentOS",; Z9 `) D& t+ |1 o) q( z
        "7.6",! w' B) `6 r( D4 D! s, \8 g7 ]5 x
        "Linux",
3 A1 R/ t' a' ]& M3 B7 J        "5.1.11-1.el7.elrepo.x86_64",% h( j0 h4 V0 W0 s) ?1 s+ U  F
        "x86_64",3 ]+ Q$ p3 d; v& G. O
        "x86_64",$ e9 R' S, f8 O0 T+ o1 y3 D' M: g  J
        "VMware",
: K$ H! J6 F& Y9 {, E        "guest",' n0 A: Z% M! U8 ]$ C& h
        "Intel(R) Core(TM) i3-4160 CPU @ 3.60GHz",+ v7 j8 l8 Q9 ?' x; J) _* X
        1,) z& o: B1 v! T
        0.9,
0 e; H, a6 q- o8 x) s        29.8,3 U& _- E2 r/ b8 O) f
        27.4  k6 |- m* u  Z/ C  Z; U
    );
( g: k! N, i5 f) W5 ?' c( i其他模板格式。; Z5 V& }9 E; J: @$ r$ K
) }! ^+ S- r- W4 O7 t" z" z

/ z9 S6 ]$ e/ N- x* U% Qansible-cmdb -t json out/
9 Z' v7 [5 O: D/ R+ uansible-cmdb -t markdown out/
您需要登录后才可以回帖 登录 | 注册

本版积分规则

返回首页|Archiver|手机版|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )

GMT+8, 2026-6-12 00:46 , Processed in 0.019287 second(s), 22 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表