零基礎學習Puppet自動化配置管理系列文檔html
注:如下內容是在foreman1.6.3+puppet2.6.2環境下進行操做。更多配置請參考官網http://theforeman.org/manuals/1.6/index.htmlnode
安裝好foreman和puppetmaster以後,接下來作的事情就是作整合,目前foreman能夠管理puppet的環境、類、類裏的變量、報告、facter等信息。接下來會逐一進行介紹。api
代理puppet以及puppetCA,須要在foreman-proxy中開啓。ssh
#配置代理puppet [root@puppetmaster162 ~]# cat /etc/foreman-proxy/settings.d/puppet.yml --- # Puppet management :enabled: true #開啓 :puppet_conf: /etc/puppet/puppet.conf # valid providers: # puppetrun (for puppetrun/kick, deprecated in Puppet 3) # mcollective (uses mco puppet) # puppetssh (run puppet over ssh) # salt (uses salt puppet.run) # customrun (calls a custom command with args) :puppet_provider: mcollective # customrun command details # Set :customrun_cmd to the full path of the script you want to run, instead of /bin/false :customrun_cmd: /bin/false # Set :customrun_args to any args you want to pass to your custom script. The hostname of the # system to run against will be appended after the custom commands. :customrun_args: -ay -f -s # whether to use sudo before the ssh command :puppetssh_sudo: false # the command which will be sent to the host :puppetssh_command: /usr/bin/puppet agent --onetime --no-usecacheonfailure # With which user should the proxy connect #:puppetssh_user: root #:puppetssh_keyfile: /etc/foreman-proxy/id_rsa # Which user to invoke sudo as to run puppet commands :puppet_user: root # URL of the puppet master itself for API requests :puppet_url: https://puppetmaster162.kisspuppet.com:8140 # SSL certificates used to access the puppet master API :puppet_ssl_ca: /var/lib/puppet/ssl/certs/ca.pem :puppet_ssl_cert: /var/lib/puppet/ssl/certs/puppetmaster162.kisspuppet.com.pem :puppet_ssl_key: /var/lib/puppet/ssl/private_keys/puppetmaster162.kisspuppet.com.pem # Override use of Puppet's API to list environments, by default it will use only if # environmentpath is given in puppet.conf, else will look for environments in puppet.conf #:puppet_use_environment_api: true #配置代理puppet ca [root@puppetmaster162 ~]# cat /etc/foreman-proxy/settings.d/puppetca.yml --- # PuppetCA management :enabled: true :ssldir: /var/lib/puppet/ssl :puppetdir: /etc/puppet
puppet從2.6版本開始增長了「目錄環境」的功能,更多詳情請訪問官網https://docs.puppetlabs.com/puppet/latest/reference/environments.htmlide
[root@puppetmaster162 ~]# cat /etc/puppet/puppet.conf [master] ... environmentpath = /etc/puppet/environments basemodulepath = /etc/puppet/modules:/usr/share/puppet/modules environment_timeout = 2 #多長時間刷新一次 [root@puppetmaster162 ~]# ll /etc/puppet/environments/ total 24 drwxr-xr-x 4 root root 4096 Dec 5 16:46 development drwxr-xr-x 4 root root 4096 Dec 5 16:46 example42 drwxr-xr-x 4 root root 4096 Dec 5 16:39 example_env drwxr-xr-x 5 root root 4096 Dec 5 17:03 production drwxr-xr-x 4 root root 4096 Dec 5 16:46 puppetlabs drwxr-xr-x 7 root root 4096 Dec 5 17:03 temp
注意:從以上配置能夠看得出設置了兩個環境。學習
3.一、配置puppet類url
注意如下幾點:spa
puppet.conf中basemodulepath的值所設置的路徑爲環境目錄下全部環境的公共環境,裏面的全部模塊都會被其餘環境搜索到(在沒有配置environment.conf的前提下)
環境目錄中每一個環境目錄裏面默認應該包含manifests(存放主配置文件site.pp)目錄和modules(存放模塊)目錄,目錄結構以下。
[root@puppetmaster162 environments]# tree production/ production/ ├── environment.conf ├── manifests │ └── site.pp ├── modules │ ├── jenkins │ │ ├── files │ │ │ └── jenkins.repo │ │ ├── manifests │ │ │ ├── init.pp │ │ │ ├── install.pp │ │ │ ├── service.pp │ │ │ └── yum.pp │ │ ├── README │ │ └── templates │ └── motd │ ├── files │ │ └── motd │ ├── manifests │ │ └── init.pp │ └── templates └── system └── ssh ├── files ├── manifests │ ├── backup.pp │ ├── config.pp │ ├── init.pp │ ├── install.pp │ └── service.pp ├── Modulefile ├── README ├── spec │ └── spec_helper.rb ├── templates │ └── sshd_config.erb └── tests └── init.pp 17 directories, 20 files
若是你想在一個環境裏包含多個目錄,每一個目錄裏面又包含模塊,應該添加environment.conf文件
[root@puppetmaster162 environments]# ll temp/ total 24 -rw-r--r-- 1 root root 95 Dec 5 17:03 environment.conf #添加環境搜索配置文件 drwxr-xr-x 11 root root 4096 Dec 5 17:02 juhailu drwxr-xr-x 2 root root 4096 Dec 5 16:48 kisspuppet drwxr-xr-x 4 root root 4096 Dec 5 16:56 lin drwxr-xr-x 2 root root 4096 Dec 5 16:48 manifests drwxr-xr-x 5 root root 4096 Dec 5 16:47 puppetlabs [root@puppetmaster162 environments]# ll temp/puppetlabs/ total 12 drwxr-xr-x 5 root root 4096 Dec 5 16:46 propuppet-demoapp drwxr-xr-x 5 root root 4096 Dec 5 16:46 puppetlabs-demoapp drwxr-xr-x 4 root root 4096 Dec 5 16:46 puppet-module-skeleton [root@puppetmaster162 environments]# cat temp/environment.conf #添加搜索路徑 modulepath = $basemodulepath:puppetlabs:modules:lin:modules:juhailu:modules:kisspuppet:modules
注意:添加搜索路徑須要添加$basemodulepath
,不然不會去搜索默認公共環境路徑。
備註:添加主類就能夠了
這樣節點和模塊就關聯上了,至關於在site.pp中添加以下代碼
node puppetmaster162.kisspuppet.com{ include ssh }
備註:若是使用組管理模塊,不建議爲某個節點單獨勾選模塊,不然你會發現若是先給節點添加了模塊A,而後再給節點對應的組裏添加了模塊A,那麼節點的puppet類哪裏就會顯示包含的類有兩個同名的模塊。
注:foreman從1.5版本開始增長了「配置組」功能,能夠將多個模塊添加到「配置組」,而後給配置組命名,這樣,主機組在勾選模塊的時候,只須要勾選配置組便可集成裏面全部的模塊
#能夠經過如下方式查看,前提是須要先運行node.rb,可經過"puppet agent"命令或者"node.rb <certname>" 進行觸發。 [root@puppetmaster162 ~]# cat /var/lib/puppet/yaml/foreman/puppetmaster162.kisspuppet.com.yaml --- classes: ssh: parameters: puppetmaster: puppetmaster162.kisspuppet.com hostgroup: prd root_pw: foreman_env: production owner_name: Admin User owner_email: root@kisspuppet.com
設置以上信息,能夠完成ENC的功能,基本能夠保障節點和class之間的勾連。能夠在節點經過puppet agent命令進行測試。至於如何在foreman上進行推送,關注後續文章。