将Puppet模块构建和导入到Katello中
为Katello构建Puppet模块。
软件
本文使用的软件:
- CentOS 7
- Katello 3.5
- Puppet4.x
Katello上的Puppet内容管理
根据最新的稳定版Katello发布文档,有两种建议的将Puppet模块导入Katello的方法:
- 从Puppet伪造导入
- 从Git导入Puppet模块
两者都有用例,但不能完全满足我们的需求。
我们希望将Puppet Forge模块与我们自己创建的模块一起使用,并使它们全部受版本控制。
这意味着只有一个包含所有Puppet模块的Katello存储库。
Katello存储库可以是包含Pulp列表和打包的Puppet模块的纯目录。
根据Pulp项目文档,Pulp列表是一个文件,列出目录中包含的每个Puppet模块。
每个模块在单独的行中列出,其格式如下:'<name>,<checksum>,<size>'。
名称是文件名,校验和是文件的SHA256摘要,大小是文件的大小(以字节为单位)。
纸浆列表必须命名为PULP_MANIFEST。
有了所有这些信息,我们就可以手动构建Puppet模块,生成Pulp列表并将所有内容导入Katello。
安装Puppet模块
我们使用之前构建的Katello服务器。
Puppet锻造
首先,我们将从Puppet Forge安装几个Puppet模块:
# puppet module install -i /etc/puppet/modules puppetlabs-firewall ;\ puppet module install -i /etc/puppet/modules puppetlabs-ntp ;\ puppet module install -i /etc/puppet/modules erwbgy-limits ;\ puppet module install -i /etc/puppet/modules thias-sysctl ;\ puppet module install -i /etc/puppet/modules spiette-selinux ;\ puppet module install -i /etc/puppet/modules Aethylred-postfix ;\ puppet module install -i /etc/puppet/modules puppetlabs-apache ;\ puppet module install -i /etc/puppet/modules puppetlabs-mysql
让我们验证一下:
# puppet module list /etc/puppet/modules ├── Aethylred-postfix (v0.2.3) ├── erwbgy-limits (v0.3.1) ├── puppet-staging (v2.0.1) ├── puppetlabs-apache (v1.10.0) ├── puppetlabs-concat (v2.2.0) ├── puppetlabs-firewall (v1.8.1) ├── puppetlabs-mysql (v3.9.0) ├── puppetlabs-ntp (v4.2.0) ├── puppetlabs-stdlib (v4.12.0) ├── spiette-selinux (v0.5.4) └── thias-sysctl (v1.0.6) /usr/share/puppet/modules (no modules installed)
生成自定义Puppet模块
转到Puppet模块目录:
# cd /etc/puppet/modules
我们将创建一个新的Puppet模块来安装rkhunter软件包。
这很简单。
生成一个新的Puppet模块:
# puppet module generate theitroad-lsn_rkhunter We need to create a metadata.json file for this module. Please answer the following questions; if the question is not applicable to this module, feel free to leave it blank. Puppet uses Semantic Versioning (semver.org) to version modules. What version is this module? [0.1.0] --> 1.0.0 Who wrote this module? [theitroad] --> What license does this module code fall under? [Apache 2.0] --> How would you describe this module in a single sentence? --> Installs rkhunter package Where is this module's source code repository? --> Where can others go to learn more about this module? --> Where can others go to file issues about this module? --> --------------------------------------- { "name": "theitroad-lsn_rkhunter", "version": "1.0.0", "author": "theitroad", "summary": "Installs rkhunter package", "license": "Apache 2.0", "source": "", "project_page": null, "issues_url": null, "dependencies": [ { "name": "puppetlabs-stdlib", "version_range": ">= 1.0.0" } ] } --------------------------------------- About to generate this metadata; continue? [n/Y] --> Notice: Generating module at /etc/puppet/modules/theitroad-lsn_rkhunter... Notice: Populating ERB templates... Finished; module generated in theitroad-lsn_rkhunter. theitroad-lsn_rkhunter/README.md theitroad-lsn_rkhunter/spec theitroad-lsn_rkhunter/spec/spec_helper.rb theitroad-lsn_rkhunter/spec/classes theitroad-lsn_rkhunter/spec/classes/init_spec.rb theitroad-lsn_rkhunter/manifests theitroad-lsn_rkhunter/manifests/init.pp theitroad-lsn_rkhunter/tests theitroad-lsn_rkhunter/tests/init.pp theitroad-lsn_rkhunter/Rakefile theitroad-lsn_rkhunter/metadata.json
打开“ theitroad-lsn_rkhunter/metadata.json”并删除依赖项,使其具有以下内容:
"dependencies": []
打开“ theitroad-lsn_rkhunter/manifests/init.pp”,然后输入以下内容:
class lsn_rkhunter { package { "rkhunter": ensure => installed, } }
再次检查模块,新模块应该列出:
# puppet module list /etc/puppet/modules ├── Aethylred-postfix (v0.2.3) ├── erwbgy-limits (v0.3.1) ├── theitroad-lsn_rkhunter (v1.0.0) ├── puppet-staging (v2.0.1) ├── puppetlabs-apache (v1.10.0) ├── puppetlabs-concat (v2.2.0) ├── puppetlabs-firewall (v1.8.1) ├── puppetlabs-mysql (v3.9.0) ├── puppetlabs-ntp (v4.2.0) ├── puppetlabs-stdlib (v4.12.0) ├── spiette-selinux (v0.5.4) └── thias-sysctl (v1.0.6) /usr/share/puppet/modules (no modules installed)
现在,我们可以继续进行构建。
为Katello构建Puppet模块
我们创建了一个方便的脚本来构建本地Puppet模块,然后可以将其导入Katello。
它可在https://github.com/crylium/build-puppet-modules-for-katello上获得,并在下面显示:
#!/bin/bash # AUTHOR: igi (www.theitroad.com) # NAME: puppet-module-build.sh # VERSION: 1.0 # DATE: 15/09/2015 (dd/mm/yy) # LICENCE: Copyleft free software ## Where Puppet modules are located MOD_DIR="/opt/puppet/modules"; MANIFEST="/opt/puppet/modules/PULP_MANIFEST"; MANIFEST_BACKUP="/opt/puppet/modules/PULP_MANIFEST.backup"; ## Sanity checks #if [ ! -d "$MOD_DIR" ]; then echo "ERROR: directory "$MOD_DIR" does not exist."; exit 1; fi if ! type puppet >/dev/null 2>&1; then echo "ERROR: Puppet is not installed."; exit 1; fi # Backup the current manifest mv -f "$MANIFEST" "$MANIFEST_BACKUP" 2>/dev/null; # Puppet module array MOD_ARRAY="$(ls -d "$MOD_DIR"/*/)"; for module in ${MOD_ARRAY[*]};do echo -e "\n$module"; puppet module build "$module" if [ -d "$module"/pkg/]; then cd "$module"/pkg/; MOD_ARCHIVE="$(ls *tar.gz)"; echo "Copying archive "$MOD_ARCHIVE"."; cp -f "$MOD_ARCHIVE" ""$MOD_DIR"/"; echo "Creating manifest "$MANIFEST" entry."; echo "$(sha256sum "$MOD_ARCHIVE"|awk '{print ","}')","$(du -b "$MOD_ARCHIVE"|awk '{print }')" >>"$MANIFEST"; else echo "ERROR: something went wrong while building '"$module"' module."; fi done
让我们克隆存储库:
# git clone https://github.com/crylium/build-puppet-modules-for-katello.git ~/git
下面将预定义的路径“/opt /”替换为我们的路径“/etc /”:
# sed -i 's/opt/etc/g' ~/git/puppet-module-build.sh
是时候构建模块了:
# bash ~/git/puppet-module-build.sh
核实:
# ls /etc/puppet/modules/ Aethylred-postfix-0.2.3.tar.gz puppetlabs-concat-2.2.0.tar.gz apache puppetlabs-firewall-1.8.1.tar.gz concat puppetlabs-mysql-3.9.0.tar.gz erwbgy-limits-0.3.1.tar.gz puppetlabs-ntp-4.2.0.tar.gz firewall puppetlabs-stdlib-4.12.0.tar.gz limits puppet-staging-2.0.1.tar.gz theitroad-lsn_rkhunter selinux theitroad-lsn_rkhunter-1.0.0.tar.gz spiette-selinux-0.5.4.tar.gz mysql staging ntp stdlib postfix sysctl PULP_MANIFEST thias-sysctl-1.0.6.tar.gz puppetlabs-apache-1.10.0.tar.gz
我们看到已经生成了PULP_MANIFEST。
现在,我们准备将模块导入Katello。
将Puppet模块导入Katello
我们在这里使用Katello WebUI,但是如果我们愿意,可以随时使用Hammer CLI。
Katello内容
Katello当前可以托管两种不同类型的内容,RPM和Puppet模块。
我们可以有产品,也可以有存储库。
简而言之,存储库是内容的集合(RPM或者Puppet模块)。
产品是存储库的集合。
当我们使用内容主机时,它们会订阅产品。
创建Katello产品
在WebUI中,导航至:“内容>产品>新产品(右上)”
Name: PuppetModules Label: PuppetModules
保存新产品。
创建一个Katello存储库
从WebUI导航至:“内容>产品> PuppetModules>存储库>创建存储库”
Name: puppet-modules Label: puppet-modules Type: puppet URL: file:///etc/puppet/modules Publish via HTTP: yes
保存新的存储库,然后对其进行同步。
我们应该看到12个Puppet模块可用。
就是这样,我们已经将模块导入了Katello。
将Puppet模块添加到Git版本控制
我们的Puppet模块不包含私有数据,因此我们可以使用公共GitHub存储库来存储它们。
存储库URL为https://github.com/home-lab/katello-puppet,我们有一个与GitHub帐户关联的SSH密钥。
这是一个测试帐户,没有真正用于其他用途。
创建一个空的Git存储库,将文件内容添加到索引,记录对存储库的更改,并更新远程引用以及相关对象:
# cd /etc/puppet/modules # echo "# katello-puppet" >> README.md # git init # git add README.md # git commit -m "first commit" # git remote add origin Hyman@theitroad:home-lab/katello-puppet.git # git push -u origin master
将所有Puppet模块提交到远程存储库:
# git add . # git commit -m "adding Puppet modules # git push origin master
现在,我们有了受版本控制的Puppet模块。