• foreman架构的引入7-Foreman结合mcollective完成push动作
  • 1、在Foreman中开启puppet插件的puppetrun功能
  • 2、配置foreman-proxy代理的puppet的puppet_provider
  • 3、配置sudoer,添加mco命令
  • 4、页面测试puppetrun按钮
  • 5、查看报告看更详细的信息

    foreman架构的引入7-Foreman结合mcollective完成push动作

    注:以下内容是在foreman1.6.3+puppet2.6.2环境下进行操作。更多配置请参考官网http://theforeman.org/manuals/1.6/index.html

    在foreman-proxy的1.6.3版本,至少提供了以下五种触发puppet agent命令的工具,默认使用的是puppetrun,不过已经过时,这里介绍如何使用mcollective进行触发,下个章节会介绍如何使用puppetssh触发。

    1. # puppetrun (for puppetrun/kick, deprecated in Puppet 3)
    2. # mcollective (uses mco puppet)
    3. # puppetssh (run puppet over ssh)
    4. # salt (uses salt puppet.run)
    5. # customrun (calls a custom command with args)

    在整个测试之前,首先要保障你的mco+mq在命令行操作的情况下是OK的。如果没有OK或者不懂什么是mco+mq,请参考之前的文章。

    如何是OK的?如下:

    1. [root@puppetmaster162 yum.repos.d]# mco puppet -v runonce
    2. Discovering hosts using the mc method for 2 second(s) .... 1
    3. * [ ============================================================> ] 1 / 1
    4. puppetmaster162.kisspuppet.com : OK
    5. {:summary=> "Started a Puppet run using the 'puppet agent --test --color=false --splay --splaylimit 30' command"}
    6. ---- rpc stats ----
    7. Nodes: 1 / 1
    8. Pass / Fail: 1 / 0
    9. Start Time: Wed Dec 17 16:22:15 +0800 2014
    10. Discovery Time: 2004.22ms
    11. Agent Time: 71.49ms
    12. Total Time: 2075.70ms

    1、在Foreman中开启puppet插件的puppetrun功能

    Foreman安装

    Foreman安装

    2、配置foreman-proxy代理的puppet的puppet_provider

    1. [root@puppetmaster162 ~]# vim /etc/foreman-proxy/settings.d/puppet.yml
    2. ---
    3. # Puppet management
    4. :enabled: true
    5. :puppet_conf: /etc/puppet/puppet.conf
    6. # valid providers:
    7. # puppetrun (for puppetrun/kick, deprecated in Puppet 3)
    8. # mcollective (uses mco puppet)
    9. # puppetssh (run puppet over ssh)
    10. # salt (uses salt puppet.run)
    11. # customrun (calls a custom command with args)
    12. :puppet_provider: mcollective
    13. ...

    3、配置sudoer,添加mco命令

    1. [root@puppetmaster162 ~]# vim /etc/sudoers.d/foreman-proxy
    2. foreman-proxy ALL = NOPASSWD : /usr/bin/puppet cert *, /usr/bin/mco puppet runonce *
    3. Defaults:foreman-proxy !requiretty
    4. [root@puppetmaster162 ~]# /etc/init.d/foreman-proxy restart
    5. Stopping foreman-proxy: [ OK ]
    6. Starting foreman-proxy: [ OK ]

    4、页面测试puppetrun按钮

    Foreman安装

    成功之后的显示

    Foreman安装

    5、查看报告看更详细的信息

    1. #可以通过日志查看执行情况
    2. [root@puppetmaster162 yum.repos.d]# tailf /var/log/foreman-proxy/proxy.log
    3. 192.168.20.11 - - [17/Dec/2014 16:25:36] "POST /run HTTP/1.1" 200 - 0.5454
    4. 以上
    5. [root@puppetmaster162 ~]# cat /etc/foreman-proxy/settings.yml
    6. ...
    7. :log_file: /var/log/foreman-proxy/proxy.log
    8. # valid options are
    9. # WARN, DEBUG, Error, Fatal, INFO, UNKNOWN
    10. :log_level: DEBUG #开启debug模式,显示更详细的信息,排错的时候使用。1.5版本之前默认是开启的
    11. [root@puppetmaster162 yum.repos.d]# tailf /var/log/foreman-proxy/proxy.log
    12. I, [2014-12-17T16:27:43.148519 #24337] INFO -- : 'foreman_proxy' settings were initialized with default values: :enabled: true
    13. W, [2014-12-17T16:27:43.155592 #24337] WARN -- : Couldn't find settings file /etc/foreman-proxy/settings.d/facts.yml. Using default settings.
    14. I, [2014-12-17T16:27:43.155860 #24337] INFO -- : 'facts' settings were initialized with default values: :enabled: true
    15. I, [2014-12-17T16:27:43.163012 #24337] INFO -- : 'dns' module is disabled.
    16. I, [2014-12-17T16:27:43.163513 #24337] INFO -- : 'tftp' module is disabled.
    17. I, [2014-12-17T16:27:43.163933 #24337] INFO -- : 'dhcp' module is disabled.
    18. I, [2014-12-17T16:27:43.579571 #24337] INFO -- : 'puppet' settings were initialized with default values: :puppetdir: /etc/puppet
    19. I, [2014-12-17T16:27:43.583486 #24337] INFO -- : 'bmc' module is disabled.
    20. I, [2014-12-17T16:27:43.583655 #24337] INFO -- : 'chefproxy' module is disabled.
    21. I, [2014-12-17T16:27:43.583934 #24337] INFO -- : 'realm' module is disabled.
    22. D, [2014-12-17T16:28:15.059328 #24344] DEBUG -- : about to execute: /usr/bin/sudo -u root /usr/bin/mco puppet runonce -I puppetmaster162.kisspuppet.com
    23. 192.168.20.11 - - [17/Dec/2014 16:28:15] "POST /run HTTP/1.1" 200 - 0.5468

    失败的情况如下:

    Foreman安装

    1. [root@puppetmaster162 ~]# tailf /var/log/foreman-proxy/proxy.log
    2. I, [2014-12-17T16:27:43.163933 #24337] INFO -- : 'dhcp' module is disabled.
    3. I, [2014-12-17T16:27:43.579571 #24337] INFO -- : 'puppet' settings were initialized with default values: :puppetdir: /etc/puppet
    4. I, [2014-12-17T16:27:43.583486 #24337] INFO -- : 'bmc' module is disabled.
    5. I, [2014-12-17T16:27:43.583655 #24337] INFO -- : 'chefproxy' module is disabled.
    6. I, [2014-12-17T16:27:43.583934 #24337] INFO -- : 'realm' module is disabled.
    7. D, [2014-12-17T16:28:15.059328 #24344] DEBUG -- : about to execute: /usr/bin/sudo -u root /usr/bin/mco puppet runonce -I puppetmaster162.kisspuppet.com
    8. 192.168.20.11 - - [17/Dec/2014 16:28:15] "POST /run HTTP/1.1" 200 - 0.5468
    9. D, [2014-12-17T16:32:56.924849 #24344] DEBUG -- : about to execute: /usr/bin/sudo -u root /usr/bin/mco puppet runonce -I puppetmaster162.kisspuppet.com
    10. 192.168.20.11 - - [17/Dec/2014 16:32:57] "POST /run HTTP/1.1" 200 - 0.6095
    11. D, [2014-12-17T16:32:57.878231 #24344] DEBUG -- : about to execute: /usr/bin/sudo -u root /usr/bin/mco puppet runonce -I foreman163.kisspuppet.com
    12. W, [2014-12-17T16:33:20.364704 #24344] WARN -- : Non-null exit code when executing '/usr/bin/sudo-uroot/usr/bin/mcopuppetrunonce-Iforeman163.kisspuppet.com'
    13. E, [2014-12-17T16:33:20.368673 #24344] ERROR -- : Failed puppet run: Check Log files
    14. 192.168.20.11 - - [17/Dec/2014 16:33:20] "POST /run HTTP/1.1" 500 34 22.4920

    备注:Foreman在命令执行后的显示这块做的其实很不好的,如何能够将所有节点执行的情况动态或者显示在界面上就更好了!