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

ansible-cmdb使用方法 安装流程

[复制链接]

1

主题

0

回帖

12

积分

管理员

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

Running from github source:

$ cd ansible-cmdb
3 D8 O: I, }2 ^0 v$ export PYTHONPATH=lib
% _. ]+ |  p1 p5 b1 f' w$ src/ansible-cmdb examples/out > ~/cmdb.html, U- p/ o2 p: X8 f1 R# D
6 N9 Y4 u+ n' C. t; {! T
$ src/ansible-cmdb -i examples/hosts examples/out > ~/cmdb.html  x# L! E5 O! x' N# K

; u2 [8 Y& K2 j- S9 B6 k$ src/ansible-cmdb -p local_js=1 -i examples/hosts examples/out > ~/cmdb.html
1 q' V8 ~. D% `2 p" f; E
. Q: |1 G, I9 M6 N; }
+ q2 h/ e, z: l* m* G8 R

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$ ~( ~0 m! h% U5 }" J4 _9 I) L: w, D) e1 D. {' D' b3 N
$ cd ansible-cmdb-*
& t- y3 T. G" @% v- R6 D" P4 ^
. B! {) b$ Y/ _$ sudo make install
  Y5 Y2 g8 {1 B$ b1 m7 X; I$ R6 L
$ ansible-cmdb out > ~/cmdb.html
6 z' m8 O! ^( |# q0 H0 d+ J6 m
3 Y, I2 I9 }# Z% y$ ansible-cmdb -i hosts out > ~/cmdb.html
" ~9 ]' h# P: M0 C3 |) i* b8 {" t5 W" A" d: Z! @0 R$ c; o
$ ansible-cmdb -p local_js=1 -i hosts out > ~/cmdb.html
" [% Z3 [2 f3 k2 e0 N! ~
/ D0 H9 x  o# _8 a  p$ cd ansible-cmdb-*
- f- {) q! M" `, x8 s
9 b% b  R6 J9 D+ P" e$ sudo make uninstall" P, t, z# n- q/ q8 O4 ]( S& E8 w1 J
6 L  j* o5 c$ h- h3 H/ I- K

+ P! T3 w6 G( C% j$ @

Installing from .deb file:


  i" d6 M% T: U$ F1 l5 d

$ dpkg -i -i ansible-cmdb-*.deb: ]3 Z3 I: n/ m7 o/ D

) q/ w/ `) o- _. \; S/ l8 @$ ?* x1 l$ ansible-cmdb out > ~/cmdb.html* K  u: T7 v. `% ]
! T- Q. k1 R8 T7 n
$ ansible-cmdb -i hosts out > ~/cmdb.html
2 P3 ^$ g$ _0 c! c+ H$ A
" @/ E9 l0 \, u. a. \/ }# m+ n$ ansible-cmdb -p local_js=1 -i hosts out > ~/cmdb.html
$ F& p+ }! q$ ?; }, Z5 ?
2 X# E, J3 N, p) l$ sudo dpkg --purge ansible-cmdb# p# c9 I$ W# b2 ~8 O. K* ^7 \

( X/ W8 x, t9 r
8 Q9 F3 K- i& L) {# J

Installing from .rpm file:

$ sudo yum install ansible-cmdb*.rpm. ~, q; |7 l- \, k4 l+ R# N8 Y( n* }
( i, d& n# @4 W- U$ e- p
$ ansible-cmdb out > ~/cmdb.html- z. f$ J8 Y, d! n8 v

. B3 N( M# G# E3 [1 O$ ansible-cmdb -i hosts out > ~/cmdb.html2 Y/ p8 z6 q4 a0 l: ~" Q+ V  A' ]

9 A: u5 R0 B3 g/ ~$ ansible-cmdb -p local_js=1 -i hosts out > ~/cmdb.html, p' T" D0 K- n3 M5 \0 d/ [
$ `) D, S# Y2 T) R+ n$ F
$ sudo yum uninstall ansible-cmdb
, u9 Y" I! w; K% ]
  P! v8 z5 Q* Q( z: i) [, U9 XLicense

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.
! @% x& C! |9 A# G7 ~  E, G6 k1 G" c/ j/ i+ i8 s

9 Y" b3 L$ V: Q/ r" @# d& P% f3 w# H8 @

5 T- M. \; a% B+ L9 z. E
. i' Z6 x+ s# O. q- a9 i5 x
& G5 o6 T3 ]: d2 x$ G4 \5 A/ R0 A+ G) P; o
7 x3 u% l3 X# Q6 b" O) d! e. e6 c, E

# \4 j2 B# R* n4 z* F3 H; R1 T4 f+ P9 U) N) y4 D

% {) b$ V9 i2 t% k1 i' {& j
' f' b% ^& t& G  q) d! Y2 I0 ^8 V
8 u* I2 x( P! m; m. f  N( L( ~% M) g7 }$ e8 \# B
Running from github source:
! j# z& w' B, c  L8 l; l
; Y* b+ F  J" K1 L0 t. G$ cd ansible-cmdb( P, e2 Y# {1 T( D6 b1 i( H
$ export PYTHONPATH=lib
0 o, z8 F6 [5 O, x8 G- _$ src/ansible-cmdb examples/out > ~/cmdb.html* h: a! f1 U  V! ?" G! P4 _
$ src/ansible-cmdb -i examples/hosts examples/out > ~/cmdb.html
9 G! t; }6 h' f, `$ src/ansible-cmdb -p local_js=1 -i examples/hosts examples/out > ~/cmdb.html$ \+ q8 Q! N- @5 }0 O( H
Installing from github source:
9 |1 O9 C+ d) g9 `* V' N( j
1 D; J, d# z# h# h$ cd ansible-cmdb
! |  B3 A. [% F1 ~4 p$ sudo python ./setup.py install
. j8 z" I& }( P! |) j- v$ ansible-cmdb ansible-cmdb/examples/out > ~/cmdb.html1 `. ]# s, U; P9 x: E
$ ansible-cmdb -i ansible-cmdb/examples/hosts ansible-cmdb/examples/out > ~/cmdb.html
# y1 ?' h% r) }$ ansible-cmdb -p local_js=1 -i ansible-cmdb/examples/hosts ansible-cmdb/examples/out > ~/cmdb.html
2 f) U" X. F0 e# j$ sudo pip uninstall mako& o5 ^* s! G" p! u1 x+ ]2 w& K
$ sudo pip uninstall pyyaml8 `+ z# ]3 m! \" I* @
$ sudo pip uninstall ansible-cmdb3 H& l# `! c/ F( f+ Q
$ sudo rm /usr/local/bin/ansible-cmdb2 b- p6 I7 `* k9 p$ D; o/ n
Installing from source tarbal:
5 Z) T- {$ o) `3 g5 M
6 R% X2 ]& \) A' i6 }$ tar -vxzf ansible-cmdb-*.tar.gz
% p" x# v$ g2 K3 u- h$ ?0 q6 d$ cd ansible-cmdb-*
6 ^( D) E1 v4 E* q$ sudo make install
8 F+ `" h2 L% y) n) O$ ansible-cmdb out > ~/cmdb.html
  l: W) @6 ]* w6 X$ ansible-cmdb -i hosts out > ~/cmdb.html% h2 l! G, h% C# e3 B
$ ansible-cmdb -p local_js=1 -i hosts out > ~/cmdb.html* K) O, g3 i) h$ C3 `; C
$ cd ansible-cmdb-*
" k8 ^- e% `. R# R7 X$ sudo make uninstall
! v2 g, Y% F9 W) l, gInstalling from .deb file:( [1 `2 I* x2 @. p1 L

, U' K7 W0 E( n3 \0 k4 z7 S8 Q$ dpkg -i -i ansible-cmdb-*.deb7 p$ ~$ j4 l$ _: J1 G
$ ansible-cmdb out > ~/cmdb.html
8 `3 f" E8 s7 T: Q7 K9 Q$ ansible-cmdb -i hosts out > ~/cmdb.html
& Y0 @) Z/ `6 q, W( i$ ansible-cmdb -p local_js=1 -i hosts out > ~/cmdb.html
3 c2 W) `* |- p3 J$ sudo dpkg --purge ansible-cmdb* c. ^+ n& i' e* [, k
Installing from .rpm file:) P0 Q) I) \0 o2 k' M. {' b* b

" l7 `) q. i/ N! W$ sudo yum install ansible-cmdb*.rpm0 N* g$ z0 o2 t+ y# \
$ ansible-cmdb out > ~/cmdb.html
8 O! t, H, Q* ^+ z/ a$ ansible-cmdb -i hosts out > ~/cmdb.html1 R. P: K% a3 z. f0 B( N$ F
$ ansible-cmdb -p local_js=1 -i hosts out > ~/cmdb.html* h+ m1 k% t& l2 @1 R, Y" `+ c
$ sudo yum uninstall ansible-cmdb
) ?2 f6 u/ Y7 Z8 r* eLicense. v" a1 R' v4 J) V3 b
Ansible-cmdb is licensed under the GPLv3:" ], l9 R( i8 Y0 c9 c& b4 m. s
4 k& G; A9 @: s9 C- [
This program is free software: you can redistribute it and/or modify% ~: D8 e0 T  g, D( j' `
it under the terms of the GNU General Public License as published by! G' `; t. h; r1 c6 m6 Z  \
the Free Software Foundation, either version 3 of the License, or
! o) U, V& `. z* ?% d) p(at your option) any later version.( \% C8 ?7 D) |, U; o+ f  d

8 t5 I6 a* W: U. f' g! P6 kThis program is distributed in the hope that it will be useful,# w4 _5 v* h1 M- y# r' O
but WITHOUT ANY WARRANTY; without even the implied warranty of
3 r( p: D7 [' {  f. UMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6 i  d0 [5 A" U! r# lGNU General Public License for more details.0 d4 D: K& K: z7 m* k
% t( [) k0 i5 K- L* ?0 t
You should have received a copy of the GNU General Public License
& N3 y& Y1 k9 }6 s. ]along with this program.  If not, see <http://www.gnu.org/licenses/>.
7 e5 E& }$ X. R* |5 P
6 R! |/ C! z! ~. T0 _4 W* I6 OFor the full license, see the LICENSE file.9 Z( q) T, Z5 Q% I7 [, a# ^

; e) H5 V& e  O& ?# d
. C, z8 ]! d+ t9 a* V& n& T2 _- r3 ~  _

2 b+ ~+ C1 L  w2 e5 i6 x* F  E' x
( \9 b+ v' W7 x, y! p

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2023-3-27 15:00:02 | 显示全部楼层
[root@jumpserver3 ~]# ansible -m setup --tree out/  -i inventory all
/ T' r& V2 `3 q9 r2 J3 Z, C- u* f  c使用ansible的setup模块收集数据生成文本文件,并存放到out目录下. N4 S- M2 l. y' z
$ q( T9 K5 r% w( @$ `2 a
ansible -i hosts -m setup --tree out/ all
8 c; a! h4 b: `
- e9 L  w' V1 n( A* W4 M
0 V' A/ Z: a& k# `: P8 `[root@jumpserver3 ~]# ansible-cmdb out/ > overview.html 8 `* J, [7 ^; w' E

7 A1 R$ T  s$ H7 K4 _+ H8 A6 o[root@jumpserver3 ~]# ansible-cmdb -c name,groups,vcpus,mem_usage,disk_usage  out/  >overview-list.html + O/ `5 B4 u" n9 T( O9 g; C
% b/ Q, K! R! P: X0 w/ G
2 d  }( C) B9 W9 S9 Q
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 指定缓存目录即可。
& F0 n1 a# J5 i- m1 ^  ~! o3 P1 d0 p9 l  b5 ]2 b% M) \# A) @

: k! |  p) H5 U7 d/ t4 q$ aansible-cmdb -f /path/to/facts/dir > overview.html
) I: I# d5 a+ @: h& H  J以资产列表得形式统计出ansible主机信息。1 V( }( j1 l/ e, ]+ M
+ A1 Q' n8 t/ d6 S3 {. O2 H1 c

/ R) D4 a; A- N" a# ansible-cmdb -t txt_table --columns name,os,ip,mem,cpus out/6 y& T3 s, _6 E4 k, \; r- C* h
Name       OS          IP              Mem  CPUs  
* v8 Y3 T6 p) y, ~---------  ----------  --------------  ---  ----  
5 b3 s) J3 o; Z( F$ alocalhost  CentOS 7.6  192.168.77.130  1g   1  * C& ~& K& t9 o1 S
输出csv格式的主机信息。# b9 F/ a5 N/ W0 g

6 A6 d; }, {1 i5 _- k* h& c- A+ d7 C8 j5 F; n. t1 R
# ansible-cmdb -t csv out/            
% e$ D- V& L  {- z% x; L' v"Name","OS","IP","Arch","Mem","MemFree","MemUsed","CPUs","Virt","Disk avail"6 Y2 Y) _1 v1 v' O
"localhost","CentOS 7.6","192.168.77.130","x86_64/x86_64","1g","0g","1g","1","VMware/guest","28.0g, 0.0g"
. N; r# W" b& t7 m7 I8 @# I输出sql文件,导入数据到mysql或者SQLite。
* t/ e, y* {3 W& B9 k
& B% W5 _0 }, l+ T" W
7 N1 h2 c) A. v! D1 D+ f9 K# ansible-cmdb -t sql out/
- W  Y, b" K. j- X6 Z8 c1 w0 XDROP TABLE IF EXISTS hosts;: A$ Q% H0 T' q8 G9 y$ ?: y
CREATE TABLE hosts (
/ L4 D4 M. L3 z% p4 |    name VARCHAR(255),6 G& @5 j2 ^5 ?+ J' |& i5 Y
    fqdn VARCHAR(255),% _/ C  ]0 R( N/ r
    main_ip VARCHAR(15),
7 G0 W' g! p1 ^. M  ?8 ~    os_name VARCHAR(80),
' h7 N( i  L2 u5 E    os_version VARCHAR(40),
; W3 g, k/ _$ I! O: x, Q    system VARCHAR(40),
3 x! l% o6 D% i    kernel VARCHAR(40),/ |! o6 E0 ~4 A9 Q3 f9 y
    arch_hardware VARCHAR(12),
0 C7 [% r/ i" O0 l2 h4 B    arch_userspace VARCHAR(12),- Z+ M' D0 j# N- W
    virt_type VARCHAR(20),; Y: _9 s" F' \2 S' W8 F  G2 P
    virt_role VARCHAR(20),
  M" I* i: m) K$ c1 X    cpu_type VARCHAR(60),& m& h) g' b$ _
    vcpus INT,) t' Q5 n4 Y& j6 f7 L/ p/ {
    ram FLOAT,7 P' e: G7 F2 c) J; o9 B/ y
    disk_total FLOAT,
4 R: ~0 E+ U. E( B$ z9 W    disk_free FLOAT  Z; T+ O! y1 z, k+ w
);
1 N0 ?5 z# o1 o2 t; f6 O9 b( c! m+ P+ O
    INSERT INTO hosts (
$ G* R9 }: Z% v$ ?9 B        name,' z; X+ K+ K0 W9 d
        fqdn,9 j9 `* X) |- B- M2 E" x  D
        main_ip,
. t( j% A9 s7 F. @3 G, d        os_name,5 [, a- Y4 j$ h, O4 a
        os_version,9 @+ n9 h! _: Q/ i% K* x" t
        system,
5 O  g: b) s  u$ _        kernel,7 w9 x- o  F' f1 q! j
        arch_hardware,
6 ]# Y% P5 F( H* F        arch_userspace,
; E8 z2 @# I5 a) Z        virt_type,
& `- E' e4 o+ g2 p        virt_role,. ^- |# Z2 k& i
        cpu_type,
* e! R5 P, h9 c; p        vcpus,
5 H# G. `( M5 G% Y        ram,: C* a% t7 n* p) U: n
        disk_total,7 ?( Q$ q' [$ K, d" L
        disk_free
8 ^0 w& Y5 B" ~7 K* q    ) VALUES (
/ Q8 L5 B- N/ P        "localhost",
% [( G0 h# i# W% |3 u        "a23-202-231-167.deploy.static.akamaitechnologies.com",
% J( D* b( F9 C2 t7 ~1 e        "192.168.77.130",: u& f/ F# [. ?8 f8 F
        "CentOS",
; }7 b" v! u1 ~2 L  u        "7.6",) ?0 K, E8 p# g
        "Linux",
1 r! p( L: F& w9 A; @        "5.1.11-1.el7.elrepo.x86_64",
* B- _/ b# q3 F        "x86_64",7 z) Q" ~/ ]" @- f; m* F' n+ V
        "x86_64",5 T  \9 o5 V; s! a
        "VMware",
3 e/ ~: h2 n" M  _1 L' S        "guest",
4 N. T: l3 d! ~. K. ~        "Intel(R) Core(TM) i3-4160 CPU @ 3.60GHz",8 p3 _' Y- z# `0 T) E
        1,
6 j$ h) E( b( U        0.9,
* }5 i. `0 X  W8 n        29.8,8 o; G+ N: s- g3 r7 J
        27.4; q. C" \' X7 ?8 s9 _) I
    );6 Q# _2 Q2 Z" ?: _9 A# e  ]& H
其他模板格式。
* p/ l! q2 T. ~* I2 Y) @& o, A2 O- B) D2 |" M! K" m& A

2 u+ a/ n. m! i5 Zansible-cmdb -t json out/
8 f/ |$ ]1 K5 @. x( _ansible-cmdb -t markdown out/
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-12 01:44 , Processed in 0.019830 second(s), 22 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

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