运维自动化之ansibleplaybook安装ruby环境-创新互联
本来不想打算写安装ruby的,但看几个puppet的群里有人对安装ruby比较茫然,所以这里简单介绍一下如何安装ruby。
为将乐等地区用户提供了全套网页设计制作服务,及将乐网站建设行业解决方案。主营业务为成都网站设计、网站建设、将乐网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!ps:话说现在也就gitlab、capistrano、puppet等软件使用ruby,最新2010年的软件好的都是python了,比如ansible、salt等。
下面是安装ruby的信息:
ruby_version: 1.9.3 ruby_dir: /usr/local gem_version: 1.8.23 bundle_version: 1.6.3
可以看到ruby的版本是1.9.3
备注:此playbook仅能对centos或者redhat的6.x版本进行安装。
下面是安装ruby的playbook结构
[root@puppet ansible]# tree roles/ruby_* roles/ruby_delete ├── files ├── handlers ├── meta │ └── main.yml ├── tasks │ ├── delete.yml │ └── main.yml ├── templates └── vars └── main.yml roles/ruby_install ├── files │ └── ruby-1.9.3.tar.gz ├── handlers ├── meta │ └── main.yml ├── tasks │ ├── copy.yml │ ├── delete.yml │ └── main.yml ├── templates └── vars └── main.yml 12 directories, 10 files
playbook安装ruby内容是
[root@puppet ansible]# cat ruby_install.yml --- - hosts: "`host`" remote_user: "`user`" gather_facts: True roles: - common - ruby_install
playbook删除ruby的内容是
[root@puppet ansible]# cat ruby_delete.yml --- - hosts: "`host`" remote_user: "`user`" gather_facts: True roles: - ruby_delete
下面是安装与测试过程
1、安装ruby
[root@puppet ansible]# time ansible-playbook ruby_install.yml --extra-vars "host=*** user=root" --private-key=/root/denglei-key.pem PLAY [***] ******************************************************************** GATHERING FACTS *************************************************************** ok: [117.121.32.107] TASK: [common | Install initializtion require software] *********************** changed: [117.121.32.107] TASK: [ruby_install | Copy Ruby Software To Redhat Client] ******************** changed: [117.121.32.107] TASK: [ruby_install | Uncompression Ruby Software To Redhat Client] *********** changed: [117.121.32.107] TASK: [ruby_install | Copy Redis Config To Redhat Client] ********************* changed: [117.121.32.107] => (item=ruby) changed: [117.121.32.107] => (item=gem) changed: [117.121.32.107] => (item=bundle) TASK: [ruby_install | Delete Ruby compression Software In Redhat Client] ****** changed: [117.121.32.107] PLAY RECAP ******************************************************************** 117.121.32.107 : ok=6 changed=5 unreachable=0 failed=0 real 0m52.274s user 0m2.863s sys 0m0.308s
2、安装后测试
06:05:26 # ll /usr/local/ total 64 drwxr-xr-x. 2 root root 4096 Sep 23 2011 bin drwxr-xr-x. 2 root root 4096 Sep 23 2011 etc drwxr-xr-x. 2 root root 4096 Sep 23 2011 games drwxr-xr-x. 2 root root 4096 Sep 23 2011 include drwxr-xr-x 2 root root 4096 Jul 15 21:55 lib drwxr-xr-x. 2 root root 4096 Sep 23 2011 lib64 drwxr-xr-x. 2 root root 4096 Sep 23 2011 libexec drwxr-xr-x 11 www www 4096 Jul 25 16:38 nginx-1.4.3 drwxr-xr-x 6 root root 4096 Jun 23 17:38 pcre-8.33 drwxr-xr-x 10 root root 4096 Jul 25 21:59 proftpd-1.3.4d drwxr-xr-x 6 root root 4096 Jul 4 20:53 ruby-1.9.3 drwxr-xr-x. 2 root root 4096 Sep 23 2011 sbin drwxr-xr-x. 5 root root 4096 May 12 2013 share drwxr-xr-x. 3 root root 4096 May 13 2013 src drwxr-xr-x 5 zabbix zabbix 4096 Jun 20 17:56 zabbix drwxr-xr-x 6 zabbix zabbix 4096 Aug 4 10:28 zabbix_proxy root@ip-10-10-32-34-test:/usr/local 06:05:29 # ruby -v ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-linux] root@ip-10-10-32-34-test:/usr/local 06:05:32 # gem -v 1.8.23 root@ip-10-10-32-34-test:/usr/local 06:05:34 # bundle -v Bundler version 1.6.3
3、删除ruby
[root@puppet ansible]# time ansible-playbook ruby_delete.yml --extra-vars "host=*** user=root" --private-key=/root/denglei-key.pem PLAY [***] ******************************************************************** GATHERING FACTS *************************************************************** ok: [117.121.32.107] TASK: [ruby_delete | Stop Ruby Service In RedHat Client] ********************** failed: [117.121.32.107] => {"changed": true, "cmd": "ps -ef|grep ruby|grep -v grep|awk '{print $2}'|xargs kill -9 >>/dev/null ", "delta": "0:00:00.021307", "end": "2014-08-05 06:06:12.093985", "item": "", "rc": 123, "start": "2014-08-05 06:06:12.072678"} stderr: usage: kill [ -s signal | -p ] [ -a ] pid ... kill -l [ signal ] ...ignoring TASK: [ruby_delete | Delete Ruby Install Dir In RedHat Client] **************** changed: [117.121.32.107] TASK: [ruby_delete | Delete Ruby Soft Link Script] **************************** changed: [117.121.32.107] => (item=ruby) changed: [117.121.32.107] => (item=gem) changed: [117.121.32.107] => (item=bundle) PLAY RECAP ******************************************************************** 117.121.32.107 : ok=4 changed=3 unreachable=0 failed=0 real 0m6.871s user 0m1.534s sys 0m0.210s
4、删除后测试
06:05:39 # ll /usr/local/ total 60 drwxr-xr-x. 2 root root 4096 Sep 23 2011 bin drwxr-xr-x. 2 root root 4096 Sep 23 2011 etc drwxr-xr-x. 2 root root 4096 Sep 23 2011 games drwxr-xr-x. 2 root root 4096 Sep 23 2011 include drwxr-xr-x 2 root root 4096 Jul 15 21:55 lib drwxr-xr-x. 2 root root 4096 Sep 23 2011 lib64 drwxr-xr-x. 2 root root 4096 Sep 23 2011 libexec drwxr-xr-x 11 www www 4096 Jul 25 16:38 nginx-1.4.3 drwxr-xr-x 6 root root 4096 Jun 23 17:38 pcre-8.33 drwxr-xr-x 10 root root 4096 Jul 25 21:59 proftpd-1.3.4d drwxr-xr-x. 2 root root 4096 Sep 23 2011 sbin drwxr-xr-x. 5 root root 4096 May 12 2013 share drwxr-xr-x. 3 root root 4096 May 13 2013 src drwxr-xr-x 5 zabbix zabbix 4096 Jun 20 17:56 zabbix drwxr-xr-x 6 zabbix zabbix 4096 Aug 4 10:28 zabbix_proxy root@ip-10-10-32-34-test:/usr/local 06:07:14 # ruby -v -bash: /usr/bin/ruby: No such file or directory root@ip-10-10-32-34-test:/usr/local 06:07:16 # gem -v -bash: /usr/bin/gem: No such file or directory root@ip-10-10-32-34-test:/usr/local 06:07:18 # bundle -v -bash: /usr/bin/bundle: No such file or directory
如果大家想使用我的例子,可以从github里下载(地址是https://github.com/dl528888/ansible-examples/tree/master/ruby_install),然后放到/etc/ansible目录里,下面是内容
创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。
本文标题:运维自动化之ansibleplaybook安装ruby环境-创新互联
转载来于:http://myzitong.com/article/cogpci.html