ameimeng 发表于 2018-8-2 13:16:10

如何将Puppet模块生成带有箭头关系依赖图

  在编写Puppet模块的时候,会存在很多依赖关系,比如配置依赖于安装包,服务依赖于配置等等,有的时候还会有虚拟资源存在,依赖更复杂,那么有没有什么办法能够直观的去看呢,答案是有的,可以通过Puppet graph选项生成资源之间的依赖关系图。
  1、安装graphviz软件包,用于转换dot文件为png格式
  
#yum install graphviz  2、在节点运行puppet命令,加上--graph参数即可
  
# puppet agent --test --environment=testing --graph  
info: Retrieving plugin
  
info: Loading facts in /var/lib/puppet/lib/facter/puppi_projects.rb
  
info: Loading facts in /var/lib/puppet/lib/facter/fact_apply.rb
  
info: Loading facts in /var/lib/puppet/lib/facter/last_run.rb
  
info: Caching catalog for puppet_linux64poc.dev.shanghaigm.com
  
info: Applying configuration version '1392080856'
  
...
  3、运行完成之后,会在本地/var/lib/puppet/state/graphs目录下生成dot文件
  
# tree /var/lib/puppet/state/graphs/  
/var/lib/puppet/state/graphs/
  
├── expanded_relationships.dot#显示详细版本的关系图

  
├──>  
└── resources.dot #显示资源的类和层次关系,但没有依赖关系
  
0 directories, 3 files
  4、利用dot命令将图片格式转换成png格式
  
# dot -Tpng -o puppet_allmodules.png /var/lib/puppet/state/graphs/relationships.dot  
# ll puppet_allmodules.png
  
-rw-r----- 1 root root 553703 Feb 11 09:08 puppet_allmodules.png
  5、打开图片查看,只截取了一部分
http://kisspuppet.com/img/puppet_graph1.jpg
页: [1]
查看完整版本: 如何将Puppet模块生成带有箭头关系依赖图