易陆发现互联网技术论坛

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

ansible-cmdb使用方法 安装流程

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

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

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

x

Running from github source:

$ cd ansible-cmdb
7 d7 `9 Q8 x: g( v& c- m$ b) J* m$ export PYTHONPATH=lib
% W1 b4 H; Y4 _3 e, [* }) }1 S' F* t$ src/ansible-cmdb examples/out > ~/cmdb.html
7 {0 C; y9 T8 n6 N; Y7 X. H- |( [8 |& w# b
$ src/ansible-cmdb -i examples/hosts examples/out > ~/cmdb.html
( g+ S. G9 m+ Z: f, y5 K
/ z  a9 ?) I: J4 W2 M  I$ src/ansible-cmdb -p local_js=1 -i examples/hosts examples/out > ~/cmdb.html
1 B! \9 O5 s- L; g5 D9 }/ F" G: ^$ l- X, A. s' w

% m" p  Y7 y5 U2 S  e

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+ Y$ E( c" c$ y% c$ ?) f# w

) h$ @/ m3 U3 a& @- G$ cd ansible-cmdb-*2 c7 b2 ?! S8 `* C/ V

% c0 {5 A+ d. p, r7 f$ sudo make install
, E2 c6 R, E' ~; [0 ?5 K) r# x( w4 q
  G  o$ C8 ]. t- h- f$ n* d$ ansible-cmdb out > ~/cmdb.html5 o) g* V8 n8 `& {

$ L6 s4 D2 i+ k9 @3 O$ ansible-cmdb -i hosts out > ~/cmdb.html
' ~. p6 X1 l2 ?
; O6 c0 P3 l8 ~$ ansible-cmdb -p local_js=1 -i hosts out > ~/cmdb.html% G; \) s& M9 P8 ~; V: j: O" `* X
5 r9 i& o4 L' N" X3 @% s% m, e' z. v
$ cd ansible-cmdb-*1 }! J) |! [" y& u2 o# m
8 K8 }0 J" B! O- r: I7 c# w
$ sudo make uninstall( Z" ~0 C* B1 a: _: Q% {9 p

9 z( f3 p+ }/ P" W  K" o
1 g. j. p/ }. e+ s% O( X- J6 U% ?) ^

Installing from .deb file:


! R+ C4 |$ @9 P2 A6 t( F! l3 D

$ dpkg -i -i ansible-cmdb-*.deb
5 R! `  ~) W: ~
  }7 `8 K/ P0 x5 p& U7 x" T$ ansible-cmdb out > ~/cmdb.html
5 s& H! h- n; Z# \7 g+ j) {' i. @3 c6 n0 N8 ]
$ ansible-cmdb -i hosts out > ~/cmdb.html
, k& p. W. p7 o
$ M- c- t3 C3 E. x$ ansible-cmdb -p local_js=1 -i hosts out > ~/cmdb.html3 O9 l7 \2 I; e8 n1 T

: Q: I% G: P" H) X% e( A, g$ sudo dpkg --purge ansible-cmdb
/ t$ u7 {5 H6 \1 [; P( m' n
3 q& ?2 [7 _+ \* v# q' z7 N$ ^8 _
# p& O) }0 l9 g6 w/ K# _

Installing from .rpm file:

$ sudo yum install ansible-cmdb*.rpm
0 s$ j- v5 @* g) U: o" W% z( L; U0 s
$ ansible-cmdb out > ~/cmdb.html
, [' c7 r' q! }  z! G4 V5 ~, `
: v8 b) b/ H, O' E8 {7 u* o8 h3 x$ ansible-cmdb -i hosts out > ~/cmdb.html
+ q) A9 @6 ^* K& C. n' F1 u1 f% Z9 F
7 r: Q2 l8 G+ k9 B1 h2 {% Y* Z$ ansible-cmdb -p local_js=1 -i hosts out > ~/cmdb.html; l( `; h: F% ]# q3 F7 W/ e, x
! X3 W, g- Z$ T6 D, ?7 U; G9 Q
$ sudo yum uninstall ansible-cmdb
- T* g  D/ j, v8 {( a+ ]( d  Z* C4 }2 V; Q) o; |1 n
License

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.
: A& E( j9 d6 v. ?1 h) [- p
; [) S# G+ n& [6 M% _5 t  r& L' Z% L7 Z

' L$ Y% V" V( F' S! O' R5 T- u9 U! ^6 \% @1 H
) V* m3 M4 x6 N$ [" c

, b+ t2 Y0 S3 ^. @- V
+ v& P' F1 f' G) G2 j, w2 S6 G5 @4 q& Y; R* d1 R

7 L4 K. q7 w+ [$ z  J" ^% Q6 d' Y. k0 p6 N  ~

, k( W4 }7 s. j: F/ q. O
( o6 N4 l$ n9 r& V9 R5 ^; P& c9 m7 m" ]% |( P6 C1 o/ U/ O) b
1 W# {1 ~6 U( ?4 T/ r0 O
Running from github source:$ a. H5 o5 X, R9 [5 I! N
8 {0 I2 z7 ~/ Q1 O
$ cd ansible-cmdb
4 G  _8 ]% s; l6 Z/ X- F" ^$ export PYTHONPATH=lib. W4 V% q* }/ q& \3 n" F
$ src/ansible-cmdb examples/out > ~/cmdb.html
6 L# g% w# z. g5 u% _$ L$ src/ansible-cmdb -i examples/hosts examples/out > ~/cmdb.html
9 ]5 W' o6 T3 w' D8 E% _# G$ src/ansible-cmdb -p local_js=1 -i examples/hosts examples/out > ~/cmdb.html5 [2 }7 Y/ c7 N; u: q- t( e8 P
Installing from github source:: L2 S4 z; {6 I- H2 y' f$ P8 M

3 Y. d9 U' o# G+ p" i" G# R" ]$ cd ansible-cmdb+ ^% ?7 E2 C5 M$ q5 B4 ?$ E9 |
$ sudo python ./setup.py install
* [1 m2 i+ D  K$ ansible-cmdb ansible-cmdb/examples/out > ~/cmdb.html
' U$ q! K. W0 E% }" n5 ]3 q' n$ ansible-cmdb -i ansible-cmdb/examples/hosts ansible-cmdb/examples/out > ~/cmdb.html
: F+ ^1 t& h- s" E( T$ ansible-cmdb -p local_js=1 -i ansible-cmdb/examples/hosts ansible-cmdb/examples/out > ~/cmdb.html) s6 p  W/ r4 S" T# X9 e( D% E# c
$ sudo pip uninstall mako) l& B* K+ c% t. m- d9 I/ `  L2 b. D
$ sudo pip uninstall pyyaml
( D/ M7 u, _" ^  s( o2 R$ sudo pip uninstall ansible-cmdb! m; s* h' C  o" V! N
$ sudo rm /usr/local/bin/ansible-cmdb/ _) K2 _+ m2 y4 ]
Installing from source tarbal:/ b5 B: R4 [: t0 h, A; f( _
. b4 ~  ?7 m) k" b% n5 T, G
$ tar -vxzf ansible-cmdb-*.tar.gz8 L% G: L# v8 f" r
$ cd ansible-cmdb-*2 }1 k& x( [  V. q2 E
$ sudo make install
; |; t; W4 K7 C9 }2 x' b: }6 V& s$ ansible-cmdb out > ~/cmdb.html, w7 r. N, n% y% W) V& J& z$ h' n
$ ansible-cmdb -i hosts out > ~/cmdb.html
3 L" u% K1 \' @* T* N6 {: a$ ansible-cmdb -p local_js=1 -i hosts out > ~/cmdb.html
( x% J2 u' y" n" s9 w$ cd ansible-cmdb-*
  p0 n: ^3 n: z  i4 _$ sudo make uninstall
! H% K; k6 z0 N- s. x" C0 MInstalling from .deb file:2 O, z8 E9 W9 z/ i

$ l( z7 O0 x6 M4 T& i; S3 o$ H* L$ dpkg -i -i ansible-cmdb-*.deb5 V( e- g% W# L( [/ M
$ ansible-cmdb out > ~/cmdb.html
7 `% @7 v; f+ |$ ansible-cmdb -i hosts out > ~/cmdb.html
9 T" R& g5 ?7 v1 j$ ansible-cmdb -p local_js=1 -i hosts out > ~/cmdb.html
- p: ~: f) N4 `1 `$ sudo dpkg --purge ansible-cmdb
/ V5 `& q, c/ P! gInstalling from .rpm file:
) T( `3 Z/ c. d2 L0 X' Z
' H6 [7 x# O5 R5 _% a1 e$ sudo yum install ansible-cmdb*.rpm2 V7 L& c$ `! K, o5 u- H
$ ansible-cmdb out > ~/cmdb.html) U) }, d  f% g8 X: @
$ ansible-cmdb -i hosts out > ~/cmdb.html( L  [, s6 I' m. B1 z
$ ansible-cmdb -p local_js=1 -i hosts out > ~/cmdb.html
9 D8 n5 Z) c( ?3 h9 v* }, B$ sudo yum uninstall ansible-cmdb
4 {( Q  H% z0 U+ U& DLicense% F+ y2 n6 d; c# E8 ~9 V
Ansible-cmdb is licensed under the GPLv3:
: G2 E6 {' X- x! l2 H* U. s3 o# x2 x& x; v
This program is free software: you can redistribute it and/or modify# i" A8 X8 m3 i$ [: k' A: q$ o
it under the terms of the GNU General Public License as published by
; L6 E% F; w, P4 Wthe Free Software Foundation, either version 3 of the License, or
; h/ v6 c' i" \' E(at your option) any later version.
5 f# u6 w5 j" v' a5 U+ Z7 G3 l2 [6 k* u$ j& t% m) y+ r. Y
This program is distributed in the hope that it will be useful,
1 l) p" M9 W. `% t, T9 jbut WITHOUT ANY WARRANTY; without even the implied warranty of
5 H8 L  w' u& r4 j) R0 `4 gMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4 i# X" I  b1 c5 Z/ `- F1 qGNU General Public License for more details.
- Z" `, A8 A$ b) ?( `  F8 t4 z1 [% e: u. `& Q
You should have received a copy of the GNU General Public License
) P1 K  e# r, V7 ?0 O3 Palong with this program.  If not, see <http://www.gnu.org/licenses/>.* B- E; n2 t* o0 o

1 q% C1 s* l& ?) I. k) C; _' @, GFor the full license, see the LICENSE file.: v# o/ w2 R& r% }, L5 S

8 U8 }/ p5 {5 x3 Q+ [
0 @+ V5 U' R7 ^8 E4 `1 t7 r7 N# ~2 e' J) J. Z8 t

6 ~4 J# \5 P+ c, q9 Q$ ?; B% Z% W& q) n7 r! E  X( i
 楼主| 发表于 2023-3-27 15:00:02 | 显示全部楼层
[root@jumpserver3 ~]# ansible -m setup --tree out/  -i inventory all- z: a7 O/ E! G( Q
使用ansible的setup模块收集数据生成文本文件,并存放到out目录下
$ H$ k; L- f! Y- N3 D- D
" a- D0 z" p0 z7 J4 ^: X8 e: Fansible -i hosts -m setup --tree out/ all6 A; L! R* k2 K/ E* P' L

+ ]0 }$ h( _* }- ?+ G8 t: s5 Y% q% D) P
[root@jumpserver3 ~]# ansible-cmdb out/ > overview.html
1 K, V! J3 b& X' B' h7 F
( _* g7 k* D8 N: N[root@jumpserver3 ~]# ansible-cmdb -c name,groups,vcpus,mem_usage,disk_usage  out/  >overview-list.html
" a0 N+ {% s" j# Q! _7 `8 s  h2 m: V+ [% A
# }7 X; h+ H9 @, ]5 {3 k% y) X
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 指定缓存目录即可。
3 J. \% j% R7 f1 z
, d$ y+ h( j# r2 D) _+ T# J1 {0 C" d1 l! p1 `
ansible-cmdb -f /path/to/facts/dir > overview.html
% m* W5 T  W" @3 C+ {; i3 J以资产列表得形式统计出ansible主机信息。$ y5 y# r# F* O) o( L  {# B

9 A- @7 q/ B+ w* m! M; I, X" a2 D8 s+ ]. M. I& C' I
# ansible-cmdb -t txt_table --columns name,os,ip,mem,cpus out/
! ^6 f) s& v& o4 C. m, q& KName       OS          IP              Mem  CPUs  
% Y8 E0 k* ?1 \+ S0 |---------  ----------  --------------  ---  ----  
# c4 C  u2 J0 ?& X  h2 ~localhost  CentOS 7.6  192.168.77.130  1g   1  - D/ z  {3 N! F6 I
输出csv格式的主机信息。
% b" t3 f) a  |$ U) X' F* a9 f  l% k, n; `
9 Y3 [2 G9 u6 l/ p3 s1 ^- g. G
# ansible-cmdb -t csv out/            
& E" w5 q) W; E1 l7 W% j"Name","OS","IP","Arch","Mem","MemFree","MemUsed","CPUs","Virt","Disk avail"
& s% b0 P6 k6 c0 H- A"localhost","CentOS 7.6","192.168.77.130","x86_64/x86_64","1g","0g","1g","1","VMware/guest","28.0g, 0.0g"% d+ o9 l) X- {
输出sql文件,导入数据到mysql或者SQLite。$ T0 ]7 c  U: q: C

6 G+ o$ V* u0 q! A
5 K0 I7 H, \8 O  z8 {8 W& D# ansible-cmdb -t sql out/! B. d: r0 J" R" Q1 {
DROP TABLE IF EXISTS hosts;% _" c' ?5 T- w" u2 O
CREATE TABLE hosts (
6 w# c8 L! ]; e) a/ c* F    name VARCHAR(255),
. a, l9 Y- L$ S4 _1 z7 I    fqdn VARCHAR(255),
, D; @1 z+ \4 A! O    main_ip VARCHAR(15),
& F4 ~+ F3 F4 @8 K  [    os_name VARCHAR(80),
1 i5 q, k: D# k0 x" ~7 C    os_version VARCHAR(40),
: X. p' y8 a5 O1 j& s( c. I    system VARCHAR(40),
" @" [" b7 e7 Q# H1 u    kernel VARCHAR(40),+ D9 e1 ^% }% W* l' ^" {0 j1 K
    arch_hardware VARCHAR(12),
* ^+ J5 P+ d: G" Q0 y3 |    arch_userspace VARCHAR(12),
/ f9 m8 e, J0 f/ q& y+ Q    virt_type VARCHAR(20),
9 M! D0 ^6 i: G! [: I5 I/ Y    virt_role VARCHAR(20),
$ X0 I4 G0 s; @- Z: m/ _, M    cpu_type VARCHAR(60),/ i3 w: C8 e4 B6 Y& j* G2 }
    vcpus INT,
# w8 N4 z% l" S4 T* T4 T    ram FLOAT,
- m0 p7 u' }$ U6 P$ ~    disk_total FLOAT,
* S) _  ]& k0 g    disk_free FLOAT
" {: k4 X$ |7 |" r- w! @% D);( y, i1 o( S1 l8 z
* w2 q, Q/ D: C; G: }
    INSERT INTO hosts (
% a1 l2 i. C5 R9 K9 L        name,4 C0 v" P0 [8 b' o: B- c
        fqdn,7 r! h& d/ f# H9 x# o8 ?
        main_ip,
% a2 `4 j- a+ z3 G' n8 W6 z( I        os_name,
3 \$ X) G/ N! ?' D+ K1 t, K: E        os_version,
7 v8 W$ V/ r* o2 G0 F. D        system,  a; g1 w' b' ^& ]& d) j
        kernel," r/ l! `6 w( B2 F0 V
        arch_hardware,
0 v/ [/ [# s- w5 D* P        arch_userspace,
4 S2 e2 y4 H$ D+ k: f. x/ ~# {        virt_type,
/ l% Q# b* a" W6 J7 ]2 I( L( j        virt_role,
, X: p. Y, j! @        cpu_type,
9 V3 S1 Y3 @5 k, x' Y* X6 z        vcpus,
/ p$ B. }8 z9 u        ram,
& i/ w( I1 I! @1 ~' z6 f) M6 ~        disk_total,& Y, X9 Q0 e0 ^5 W2 X9 d
        disk_free
3 x; _5 ^- l' h    ) VALUES (
" |4 c, Y  Y: q        "localhost",
+ f: \& p, C. G0 M  Z1 a! t        "a23-202-231-167.deploy.static.akamaitechnologies.com",. x$ F3 O3 y/ ]5 j2 l! |- U# |0 L
        "192.168.77.130",3 [/ n" @2 ^  P: z: \& n/ ^
        "CentOS",
! ?1 [$ `# p4 v/ C        "7.6",
  h  X! V+ r2 t$ }4 n+ K  ^        "Linux",
: X) _. m7 }( r4 I8 m8 ~        "5.1.11-1.el7.elrepo.x86_64",' {; n' G3 T4 ~% n- k% |' S
        "x86_64",5 v- ]( U4 ?6 Y( W- I& ?  A! l
        "x86_64",
! D) T: f  t) Y# q* E8 W        "VMware",
# T0 }4 d4 t: Z/ w/ d; ^0 o) [        "guest",2 F( _) L2 U, K; n3 l
        "Intel(R) Core(TM) i3-4160 CPU @ 3.60GHz",
$ I) a1 q' H2 N# p0 F. `        1,* s9 w/ L- C4 a, U
        0.9,
7 h5 j; O2 ?% E9 f9 ^        29.8,
) b/ J# V3 _+ U2 E" B        27.4
+ ~8 c. I5 O4 l6 L/ h% F8 L    );
+ P# c7 p# k" O其他模板格式。+ R5 @' T! w3 x5 x5 m+ U

7 ]8 F1 v8 g/ W% P& A/ L
  V8 I$ i" E$ x4 n" `8 Kansible-cmdb -t json out/ 0 ]# C( i2 t( Q) t  X' k
ansible-cmdb -t markdown out/
您需要登录后才可以回帖 登录 | 开始注册

本版积分规则

关闭

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

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

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

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

Powered by Discuz! X3.4 Licensed

© 2012-2025 Discuz! Team.

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