运维自动化之ansible playbook安装ruby环境
本来不想打算写安装ruby的,但看几个puppet的群里有人对安装ruby比较茫然,所以这里简单介绍一下如何安装ruby。
ps:话说现在也就gitlab、capistrano、puppet等软件使用ruby,最新2010年的软件好的都是python了,比如ansible、salt等。
下面是安装ruby的信息:
ruby_version:1.9.3ruby_dir:/usr/localgem_version:1.8.23bundle_version:1.6.3
可以看到ruby的版本是1.9.3
备注:此playbook仅能对centos或者redhat的6.x版本进行安装。
下面是安装ruby的playbook结构
[root@puppetansible]#treeroles/ruby_*roles/ruby_delete├──files├──handlers├──meta│└──main.yml├──tasks│├──delete.yml│└──main.yml├──templates└──vars└──main.ymlroles/ruby_install├──files│└──ruby-1.9.3.tar.gz├──handlers├──meta│└──main.yml├──tasks│├──copy.yml│├──delete.yml│└──main.yml├──templates└──vars└──main.yml12directories,10files
playbook安装ruby内容是
[root@puppetansible]#catruby_install.yml----hosts:"`host`"remote_user:"`user`"gather_facts:Trueroles:-common-ruby_install
playbook删除ruby的内容是
[root@puppetansible]#catruby_delete.yml----hosts:"`host`"remote_user:"`user`"gather_facts:Trueroles:-ruby_delete
下面是安装与测试过程
1、安装ruby
[root@puppetansible]#timeansible-playbookruby_install.yml--extra-vars"host=***user=root"--private-key=/root/denglei-key.pemPLAY[***]********************************************************************GATHERINGFACTS***************************************************************ok:[117.121.32.107]TASK:[common|Installinitializtionrequiresoftware]***********************changed:[117.121.32.107]TASK:[ruby_install|CopyRubySoftwareToRedhatClient]********************changed:[117.121.32.107]TASK:[ruby_install|UncompressionRubySoftwareToRedhatClient]***********changed:[117.121.32.107]TASK:[ruby_install|CopyRedisConfigToRedhatClient]*********************changed:[117.121.32.107]=>(item=ruby)changed:[117.121.32.107]=>(item=gem)changed:[117.121.32.107]=>(item=bundle)TASK:[ruby_install|DeleteRubycompressionSoftwareInRedhatClient]******changed:[117.121.32.107]PLAYRECAP********************************************************************117.121.32.107:ok=6changed=5unreachable=0failed=0real0m52.274suser0m2.863ssys0m0.308s
2、安装后测试
06:05:26#ll/usr/local/total64drwxr-xr-x.2rootroot4096Sep232011bindrwxr-xr-x.2rootroot4096Sep232011etcdrwxr-xr-x.2rootroot4096Sep232011gamesdrwxr-xr-x.2rootroot4096Sep232011includedrwxr-xr-x2rootroot4096Jul1521:55libdrwxr-xr-x.2rootroot4096Sep232011lib64drwxr-xr-x.2rootroot4096Sep232011libexecdrwxr-xr-x11wwwwww4096Jul2516:38nginx-1.4.3drwxr-xr-x6rootroot4096Jun2317:38pcre-8.33drwxr-xr-x10rootroot4096Jul2521:59proftpd-1.3.4ddrwxr-xr-x6rootroot4096Jul420:53ruby-1.9.3drwxr-xr-x.2rootroot4096Sep232011sbindrwxr-xr-x.5rootroot4096May122013sharedrwxr-xr-x.3rootroot4096May132013srcdrwxr-xr-x5zabbixzabbix4096Jun2017:56zabbixdrwxr-xr-x6zabbixzabbix4096Aug410:28zabbix_proxyroot@ip-10-10-32-34-test:/usr/local06:05:29#ruby-vruby1.9.3p392(2013-02-22revision39386)[x86_64-linux]root@ip-10-10-32-34-test:/usr/local06:05:32#gem-v1.8.23root@ip-10-10-32-34-test:/usr/local06:05:34#bundle-vBundlerversion1.6.3
3、删除ruby
[root@puppetansible]#timeansible-playbookruby_delete.yml--extra-vars"host=***user=root"--private-key=/root/denglei-key.pemPLAY[***]********************************************************************GATHERINGFACTS***************************************************************ok:[117.121.32.107]TASK:[ruby_delete|StopRubyServiceInRedHatClient]**********************failed:[117.121.32.107]=>{"changed":true,"cmd":"ps-ef|grepruby|grep-vgrep|awk'{print$2}'|xargskill-9>>/dev/null","delta":"0:00:00.021307","end":"2014-08-0506:06:12.093985","item":"","rc":123,"start":"2014-08-0506:06:12.072678"}stderr:usage:kill[-ssignal|-p][-a]pid...kill-l[signal]...ignoringTASK:[ruby_delete|DeleteRubyInstallDirInRedHatClient]****************changed:[117.121.32.107]TASK:[ruby_delete|DeleteRubySoftLinkScript]****************************changed:[117.121.32.107]=>(item=ruby)changed:[117.121.32.107]=>(item=gem)changed:[117.121.32.107]=>(item=bundle)PLAYRECAP********************************************************************117.121.32.107:ok=4changed=3unreachable=0failed=0real0m6.871suser0m1.534ssys0m0.210s
4、删除后测试
06:05:39#ll/usr/local/total60drwxr-xr-x.2rootroot4096Sep232011bindrwxr-xr-x.2rootroot4096Sep232011etcdrwxr-xr-x.2rootroot4096Sep232011gamesdrwxr-xr-x.2rootroot4096Sep232011includedrwxr-xr-x2rootroot4096Jul1521:55libdrwxr-xr-x.2rootroot4096Sep232011lib64drwxr-xr-x.2rootroot4096Sep232011libexecdrwxr-xr-x11wwwwww4096Jul2516:38nginx-1.4.3drwxr-xr-x6rootroot4096Jun2317:38pcre-8.33drwxr-xr-x10rootroot4096Jul2521:59proftpd-1.3.4ddrwxr-xr-x.2rootroot4096Sep232011sbindrwxr-xr-x.5rootroot4096May122013sharedrwxr-xr-x.3rootroot4096May132013srcdrwxr-xr-x5zabbixzabbix4096Jun2017:56zabbixdrwxr-xr-x6zabbixzabbix4096Aug410:28zabbix_proxyroot@ip-10-10-32-34-test:/usr/local06:07:14#ruby-v-bash:/usr/bin/ruby:Nosuchfileordirectoryroot@ip-10-10-32-34-test:/usr/local06:07:16#gem-v-bash:/usr/bin/gem:Nosuchfileordirectoryroot@ip-10-10-32-34-test:/usr/local06:07:18#bundle-v-bash:/usr/bin/bundle:Nosuchfileordirectory
如果大家想使用我的例子,可以从github里下载(地址是https://github.com/dl528888/ansible-examples/tree/master/ruby_install),然后放到/etc/ansible目录里,下面是内容
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。