易陆发现互联网技术论坛

 找回密码
 开始注册
查看: 557|回复: 3
收起左侧

ansible-cmdb使用方法 安装流程

[复制链接]
发表于 2023-3-27 15:00:01 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?开始注册

x

Running from github source:

$ cd ansible-cmdb+ a& ]; q/ c- x6 l- e) B2 v7 t/ \
$ export PYTHONPATH=lib$ |8 }) L% S# k3 ?
$ src/ansible-cmdb examples/out > ~/cmdb.html$ a) D1 h' Z5 p* H3 P
0 e4 n  V# F+ v6 u5 `3 q
$ src/ansible-cmdb -i examples/hosts examples/out > ~/cmdb.html
. h! @2 w% L: h5 R
( `3 |. n* y8 _3 s  ]9 k2 a7 ]$ K+ T$ src/ansible-cmdb -p local_js=1 -i examples/hosts examples/out > ~/cmdb.html
8 e, E; m' I* k( U; g, S/ O/ D# H' V6 P
: A2 H) s& P$ @

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.gz9 U+ ]! i9 O) J" v5 p
. `! U( {. u; q% e- v
$ cd ansible-cmdb-*( e/ E4 D8 O" N4 E) {5 d2 S, F9 ]
3 A* o1 r1 R9 ~  D; R
$ sudo make install
0 A6 f: x# }1 G
1 R4 F% ~- Q' T* s. h$ ansible-cmdb out > ~/cmdb.html2 v7 w6 ]) t* i9 g8 @

) Q; V/ f1 D0 P; }2 C7 X' q$ ansible-cmdb -i hosts out > ~/cmdb.html" `" g" I9 b: P# C. w8 a

+ m3 B" ^$ x1 O0 E0 h$ ansible-cmdb -p local_js=1 -i hosts out > ~/cmdb.html
1 w1 v( Y( _; ~  v) V- }9 }
* J; [& b+ Y4 f1 L$ cd ansible-cmdb-*
0 H! Z0 s$ I2 C
/ [) T4 s1 v7 |6 k$ sudo make uninstall
0 z" X4 ?4 A9 n; B. h" ^$ p& o1 Z
, M: L; |4 M  r* D2 p
! n: v* {- O4 I: }

Installing from .deb file:


$ F1 S8 [  ?$ K% ~  l. L

$ dpkg -i -i ansible-cmdb-*.deb
& G! T5 n$ o5 _7 K. R( c8 N! g& v5 S, [3 ?2 x$ y: ^5 _1 r, }4 d2 @  W
$ ansible-cmdb out > ~/cmdb.html- K# R, U( Y! B% |+ I( ^7 A8 e

4 E! l/ t. o* J# @$ M. h2 s$ ansible-cmdb -i hosts out > ~/cmdb.html
% T" {" s5 N. F2 r2 l6 V9 W9 H
+ N# z8 m/ O) N( ?$ ansible-cmdb -p local_js=1 -i hosts out > ~/cmdb.html
% t0 G: P+ y3 T7 O* f) [! z! |, Q3 {1 a4 b
$ sudo dpkg --purge ansible-cmdb
* c# D( _5 R* ~- d
+ e# E7 j1 f/ [( h
" M% K  B: Z* {7 i7 ?8 W

Installing from .rpm file:

$ sudo yum install ansible-cmdb*.rpm2 |+ i* l7 f3 Z! A, _' ~9 M6 S
, L8 D, X' G! C' d- V7 _! {
$ ansible-cmdb out > ~/cmdb.html' `# h9 I; e3 W- W: _7 f

  o5 H& E/ R2 F; ]; h$ ansible-cmdb -i hosts out > ~/cmdb.html
8 e- }% S- `0 z& t) {. C) T, a  B3 |& s6 \
$ ansible-cmdb -p local_js=1 -i hosts out > ~/cmdb.html
, G9 T) C& s' N# b7 U; I) a; R8 L6 s0 t+ |+ ?% l% a
$ sudo yum uninstall ansible-cmdb4 j: j! c: F$ w% [0 _" l, o

0 ]5 p9 i$ L/ R# g; `" h# [2 w7 Y; PLicense

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.
. L8 N  }* G2 Z! X, u: O1 p4 |: H

2 s" f; H# f' ]. P" p: i: [2 ~* U! h* X) z7 x+ T

2 v# h# e1 l/ X' h9 k% r3 D0 `5 O: Y; S& u4 n1 L. J2 W

/ F# v  a% V  X  Q3 R# ?3 G6 A( I9 |6 H
* ?+ B+ ?" ?% N0 J, F2 K
. z! i0 s2 \3 e$ Y7 x; G/ P
( e" |" b" p" c* K
6 f% }! Y& ~& f( e' a2 B
7 y) q3 X5 {, t1 |- G4 Y" P
5 _8 t4 y* S% _8 O2 W2 O

# ?  L; Y  d& C. p" g1 {Running from github source:5 k: \' W8 E! }, ]) h% M) T, @

' U( P" o* q2 V$ ]$ cd ansible-cmdb& }9 k; t5 R1 ?! t0 g# n9 ]# [* L
$ export PYTHONPATH=lib
) r: D. I: w" x6 C: \$ src/ansible-cmdb examples/out > ~/cmdb.html
$ I- _% ?: b: ]. h4 ^2 F$ src/ansible-cmdb -i examples/hosts examples/out > ~/cmdb.html8 I( @/ ^# R# @: h" T- q3 Y- d
$ src/ansible-cmdb -p local_js=1 -i examples/hosts examples/out > ~/cmdb.html2 Q4 W. Q" z! I0 a; G* O8 a6 W
Installing from github source:
8 K; j3 M$ z# M$ K2 u
% I8 V- L+ Q' D, T$ cd ansible-cmdb
6 J: \8 E4 b9 r$ sudo python ./setup.py install
7 N9 ?2 ~' x) ]: T- y! x$ i' D$ ansible-cmdb ansible-cmdb/examples/out > ~/cmdb.html- i+ Q% h' {1 w& ~& f$ M# I2 Q
$ ansible-cmdb -i ansible-cmdb/examples/hosts ansible-cmdb/examples/out > ~/cmdb.html5 Z) {: [2 X- b
$ ansible-cmdb -p local_js=1 -i ansible-cmdb/examples/hosts ansible-cmdb/examples/out > ~/cmdb.html4 @5 J9 _9 A% d* v/ U" P; s
$ sudo pip uninstall mako$ N- t! Q, ^0 Q% |
$ sudo pip uninstall pyyaml
) a7 b) V# M, p" H; Z' z$ sudo pip uninstall ansible-cmdb  k$ l" T5 [4 C2 i+ i$ v  u2 o; v
$ sudo rm /usr/local/bin/ansible-cmdb/ \4 w3 n. [! t" X; G/ b1 I
Installing from source tarbal:% e: m2 }8 Q) H* Z$ T

4 q  x. ~$ V$ o# i# h5 z! h% F$ tar -vxzf ansible-cmdb-*.tar.gz: H0 X( ^: S6 ^2 X! x
$ cd ansible-cmdb-*
5 _+ c7 g$ m' l5 G) B4 I# Z6 c$ sudo make install2 U6 h8 L2 [0 S4 M* \2 x' k, v
$ ansible-cmdb out > ~/cmdb.html
" O( V; ~% \9 B' D, F$ ansible-cmdb -i hosts out > ~/cmdb.html+ C4 {4 f; U0 g& O, n& i
$ ansible-cmdb -p local_js=1 -i hosts out > ~/cmdb.html4 K$ L7 u. T& h9 Q! C
$ cd ansible-cmdb-*
* j5 a3 h* l7 u* ?$ sudo make uninstall0 i5 B6 K3 u3 `+ ~2 `
Installing from .deb file:
2 C3 h: O; O6 i0 p) r
8 D! s- a( @: h$ dpkg -i -i ansible-cmdb-*.deb% u7 k& P: @! I: C7 M8 ^
$ ansible-cmdb out > ~/cmdb.html
& H) a! T+ M: A$ ansible-cmdb -i hosts out > ~/cmdb.html6 [5 t# t) N9 {$ |- S% L+ d
$ ansible-cmdb -p local_js=1 -i hosts out > ~/cmdb.html
$ M0 ^* x" T' x! q* \2 ?* k! e$ sudo dpkg --purge ansible-cmdb6 ]- {$ u7 _) o9 h
Installing from .rpm file:2 O2 [* T3 t  Z) J; u0 b* O" M3 Y

) F' ?4 N2 f; y5 h4 w$ sudo yum install ansible-cmdb*.rpm1 [3 P, i5 |5 D) B) w4 O$ |
$ ansible-cmdb out > ~/cmdb.html" q3 l: G! i3 e! i* T% U) _& R
$ ansible-cmdb -i hosts out > ~/cmdb.html
! Y( t3 H+ y( b6 f( P5 h( J$ ansible-cmdb -p local_js=1 -i hosts out > ~/cmdb.html
" k$ r8 N# i! s; k$ sudo yum uninstall ansible-cmdb
3 ?' W( F8 Q2 m! K: L  JLicense
; |- ]5 ?5 ]% }$ q& pAnsible-cmdb is licensed under the GPLv3:
1 Q; G9 d/ [2 G# R  r
! v6 r, B& J% T. KThis program is free software: you can redistribute it and/or modify- O, g- r4 J- N
it under the terms of the GNU General Public License as published by
' X* b( w) k4 uthe Free Software Foundation, either version 3 of the License, or; m- ^: O5 `: D- r& d! L
(at your option) any later version.5 u7 e- T4 k6 n2 o6 U, T
- d5 q  L! \' V1 A% _
This program is distributed in the hope that it will be useful,. `, h( t; D2 s4 n" H. P9 l8 m. {3 ~
but WITHOUT ANY WARRANTY; without even the implied warranty of( e/ j  O9 `% `( c+ U
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  l; }7 c" E- M1 C
GNU General Public License for more details.: h0 E' u, a) R+ G
$ {2 ?# w7 b" \% G
You should have received a copy of the GNU General Public License. ~* |6 N5 o& w  D' D8 H
along with this program.  If not, see <http://www.gnu.org/licenses/>.
/ E, E5 v# c. |9 S/ y2 Q9 s8 ~- Y+ Q( Q, g: c7 @& V
For the full license, see the LICENSE file.6 r. ^! Y4 k& @! e: N4 h" E* z, g
8 H; }/ ^2 j2 }4 a- O6 I
' B, }' P2 z; _. z5 c

/ u$ g7 [$ R% x1 D& K! U2 ?: x8 ]5 Q# S, S  t/ o

0 q, t- L9 G0 ]: v* t$ P
 楼主| 发表于 2023-3-27 15:00:02 | 显示全部楼层
[root@jumpserver3 ~]# ansible -m setup --tree out/  -i inventory all
7 p; y  B+ K. G+ g& G7 ?使用ansible的setup模块收集数据生成文本文件,并存放到out目录下
" t* _2 f8 T3 Y7 e. m: D( \2 t" B$ j" _" b- G
ansible -i hosts -m setup --tree out/ all
2 r6 W& p8 w$ ~" h/ l9 s. f( c' M
& C6 R& U; W: r$ K( t  v5 o7 F- |! M0 q. ?5 b5 m3 x# s
[root@jumpserver3 ~]# ansible-cmdb out/ > overview.html 4 z; Z# h# t2 F& T; w
; ?% _9 O: V9 v! K: B. ]
[root@jumpserver3 ~]# ansible-cmdb -c name,groups,vcpus,mem_usage,disk_usage  out/  >overview-list.html
' v+ C1 S' `5 @: H5 E
% X" X1 |, D  M& m& ~
  @$ W9 c4 w( Z. I9 e5 K3 Y$ U% }ansible-cmdb -t /usr/local/lib/ansible-cmdb/ansiblecmdb/data/tpl/csv.tpl  out/ > cmdb.csv
 楼主| 发表于 2023-3-27 15:00:03 | 显示全部楼层
[root@jumpserver3 ~]# ansible -m setup -t html_fancy_split --tree  out/  -i inventory all
 楼主| 发表于 2023-4-19 14:26:15 | 显示全部楼层
如果facts用了本地缓存,-f 指定缓存目录即可。5 |& ]5 V5 |4 y/ G) {6 I* G; C; U& t$ Q

) r# h6 ~+ }5 r; W- v' O5 ^- Z6 \$ t( `* V' V) s& ?
ansible-cmdb -f /path/to/facts/dir > overview.html
; Y6 \  x- o8 h9 a9 V以资产列表得形式统计出ansible主机信息。
0 b& |& S  j  _* p9 F2 |) w/ }% g$ o" D- N5 K8 G

5 I3 s  ~" ?. e+ I2 ^0 G+ w# ansible-cmdb -t txt_table --columns name,os,ip,mem,cpus out/. [9 \' D' c  p  ?5 I: i: Q
Name       OS          IP              Mem  CPUs  8 [+ o7 Q8 ]- }& C0 ^6 `
---------  ----------  --------------  ---  ----  
! {1 S* q% M/ E. I) Vlocalhost  CentOS 7.6  192.168.77.130  1g   1  
& [7 I4 k+ i* y9 k$ L' t( K7 a3 j输出csv格式的主机信息。- X7 h# z, l. C6 ~

& d/ i1 I+ v1 K
5 Q$ J- e) }7 J  Q( L% `# ansible-cmdb -t csv out/             6 i& f; E* u$ b% R8 F
"Name","OS","IP","Arch","Mem","MemFree","MemUsed","CPUs","Virt","Disk avail"7 u0 c- a4 }' x: l4 e
"localhost","CentOS 7.6","192.168.77.130","x86_64/x86_64","1g","0g","1g","1","VMware/guest","28.0g, 0.0g"; R8 @$ `+ m) K% p: ^
输出sql文件,导入数据到mysql或者SQLite。6 q3 {$ c0 A* O

& r( G/ S1 ?* @6 ], {
. G. U" h+ p6 l$ y0 ]8 }+ ]# ansible-cmdb -t sql out/7 R3 S8 u& Q  T1 T
DROP TABLE IF EXISTS hosts;
, K" P0 C6 i) U) Y) l7 MCREATE TABLE hosts (
7 Y( ~  _7 j" ?9 h4 [    name VARCHAR(255),
$ ?% A: A+ C1 Y; o7 b    fqdn VARCHAR(255),
8 d5 O# l+ Y7 N# @    main_ip VARCHAR(15),
$ D1 D. H7 A* N( ~* @    os_name VARCHAR(80),
$ {& A3 s; J" j+ i- k4 ~$ H    os_version VARCHAR(40),
/ N2 B) t+ H1 Y! J9 b! r    system VARCHAR(40),- ~+ ~4 M0 f, f# }+ e. f/ C
    kernel VARCHAR(40),/ V, Q: k; S: z# }
    arch_hardware VARCHAR(12),
8 b7 z( W; n# O& D    arch_userspace VARCHAR(12),6 @3 u9 f( I7 X! t: N
    virt_type VARCHAR(20),
- l' J* c, k6 \$ \! S( P3 _    virt_role VARCHAR(20),# e1 l1 `) B0 ~; v5 ]) A# x# t
    cpu_type VARCHAR(60),+ u- o- |+ N6 b$ {
    vcpus INT,
/ d5 u1 I* ~; X: d) O    ram FLOAT,
$ H0 J8 x% z% Y/ A    disk_total FLOAT,
. |$ D: Y; g5 F' K& k$ q8 L; _    disk_free FLOAT
- {6 \! M% k2 B9 K; X, K);% R2 M8 u/ T! K- {; c2 d

4 h: X3 A' `! l% d9 F    INSERT INTO hosts (
/ K2 M% f  R9 f& @2 W" D. c3 H        name,
$ @; x1 K8 S$ p0 B; h( S        fqdn,
/ V0 M4 R- p, N, O4 t, V; O% w/ [        main_ip,1 h& H) z$ q' y+ @* x  K7 G6 [" X9 g" l
        os_name,
. L/ z- ?3 `- h! {: o0 U: y/ E        os_version,& f; M0 F7 c' D+ m! |6 q
        system,  Z$ ^2 d6 N3 |7 l
        kernel,
* m3 M" Z$ @6 ~: [        arch_hardware,
0 E5 W1 M! t7 M$ L6 ]        arch_userspace,
1 {& _, ?8 m- y( a2 F' H        virt_type,' P1 I- r2 p& h& O
        virt_role,- i$ E( q5 t% v0 H
        cpu_type,: o$ K  f' l# V
        vcpus,
' L; I9 F% t" e7 X" N) c) W8 _        ram,1 q) a* _3 @: S; E
        disk_total,( W8 c, e# W2 i2 X
        disk_free
; H' U/ N" Y! X& Z    ) VALUES (5 I$ b2 S7 ?; h5 @0 L
        "localhost",
6 p7 u' s1 c9 G* w, G1 R3 p. Z        "a23-202-231-167.deploy.static.akamaitechnologies.com",
$ c7 j  r$ {2 @2 \' }  ?7 |        "192.168.77.130",. l6 K$ i" n2 [  P6 ~) \  W9 @
        "CentOS",0 |) C/ y4 j8 K2 x7 p
        "7.6",
) y7 u4 v: [3 `$ H5 d- M1 h% P        "Linux",
2 [' C5 Q/ f  F8 }( M& \0 Q        "5.1.11-1.el7.elrepo.x86_64",
+ K' }. n  s/ W* f  j9 z        "x86_64",/ }: e; ^3 n! `5 b. @# e
        "x86_64",& a! x. i3 c5 y& k' Q6 \* @
        "VMware",4 D, g; L2 {  ^* q3 N: f0 {0 v
        "guest",- E+ |4 W/ F5 T1 S
        "Intel(R) Core(TM) i3-4160 CPU @ 3.60GHz",+ w7 _9 E, ~# v* C2 B) R
        1,2 L" }/ Y9 @# C" N# a4 ^% Q+ u
        0.9,
8 e4 h8 j0 ?! E2 E8 s  o        29.8,
. U7 l* |  p- L8 b! u" d        27.4
7 _3 `3 `' W2 W% l1 P    );
5 c+ X5 z; L  M8 V7 e  E3 i2 V其他模板格式。: Q1 j# j) `5 o
- w! A+ B1 {5 J, W/ W9 {6 r
0 r9 _5 P0 {4 q! a% G
ansible-cmdb -t json out/
3 t  G! O- v3 r" Bansible-cmdb -t markdown out/
您需要登录后才可以回帖 登录 | 开始注册

本版积分规则

关闭

站长推荐上一条 /4 下一条

北京云银创陇科技有限公司以云计算运维,代码开发

QQ|返回首页|Archiver|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )点击这里给我发消息

GMT+8, 2026-4-8 21:39 , Processed in 0.055593 second(s), 22 queries .

Powered by Discuz! X3.4 Licensed

© 2012-2025 Discuz! Team.

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