I didn't want to write or install Ruby, but some people in several puppet groups are confused about Ruby installation. So here I will briefly introduce how to install Ruby.
PS: Now gitlab, Capistrano, puppet, and other software use Ruby. The latest software in 2010 is Python, such as ansible and salt.
The information for installing Ruby is as follows:
ruby_version: 1.9.3ruby_dir: /usr/localgem_version: 1.8.23bundle_version: 1.6.3
The ruby version is 1.9.3.
Note: This playbook can only be installed in centos or 6.x of RedHat.
The following is the playbook structure for installing Ruby:
[[email protected] ansible]# tree roles/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.yml12 directories, 10 files
Playbook Ruby installation content is
[[email protected] ansible]# cat ruby_install.yml ---- hosts: "{{host}}" remote_user: "{{user}}" gather_facts: True roles: - common - ruby_install
Playbook deletes Ruby content
[[email protected] ansible]# cat ruby_delete.yml ---- hosts: "{{host}}" remote_user: "{{user}}" gather_facts: True roles: - ruby_delete
The installation and testing process is as follows:
1. Install Ruby
[[email protected] ansible]# time ansible-playbook ruby_install.yml --extra-vars "host=vpn user=root" --private-key=/root/denglei-key.pem PLAY [vpn] ******************************************************************** 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 real0m52.274suser0m2.863ssys0m0.308s
2. Test after installation
06:05:26 # ll /usr/local/total 64drwxr-xr-x. 2 root root 4096 Sep 23 2011 bindrwxr-xr-x. 2 root root 4096 Sep 23 2011 etcdrwxr-xr-x. 2 root root 4096 Sep 23 2011 gamesdrwxr-xr-x. 2 root root 4096 Sep 23 2011 includedrwxr-xr-x 2 root root 4096 Jul 15 21:55 libdrwxr-xr-x. 2 root root 4096 Sep 23 2011 lib64drwxr-xr-x. 2 root root 4096 Sep 23 2011 libexecdrwxr-xr-x 11 www www 4096 Jul 25 16:38 nginx-1.4.3drwxr-xr-x 6 root root 4096 Jun 23 17:38 pcre-8.33drwxr-xr-x 10 root root 4096 Jul 25 21:59 proftpd-1.3.4ddrwxr-xr-x 6 root root 4096 Jul 4 20:53 ruby-1.9.3drwxr-xr-x. 2 root root 4096 Sep 23 2011 sbindrwxr-xr-x. 5 root root 4096 May 12 2013 sharedrwxr-xr-x. 3 root root 4096 May 13 2013 srcdrwxr-xr-x 5 zabbix zabbix 4096 Jun 20 17:56 zabbixdrwxr-xr-x 6 zabbix zabbix 4096 Aug 4 10:28 zabbix_proxy[email protected]:/usr/local06:05:29 # ruby -vruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-linux][email protected]:/usr/local06:05:32 # gem -v1.8.23[email protected]:/usr/local06:05:34 # bundle -vBundler version 1.6.3
3. Delete Ruby
[[email protected] ansible]# time ansible-playbook ruby_delete.yml --extra-vars "host=vpn user=root" --private-key=/root/denglei-key.pem PLAY [vpn] ******************************************************************** 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 ]...ignoringTASK: [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 real0m6.871suser0m1.534ssys0m0.210s
4. Test after deletion
06:05:39 # ll /usr/local/total 60drwxr-xr-x. 2 root root 4096 Sep 23 2011 bindrwxr-xr-x. 2 root root 4096 Sep 23 2011 etcdrwxr-xr-x. 2 root root 4096 Sep 23 2011 gamesdrwxr-xr-x. 2 root root 4096 Sep 23 2011 includedrwxr-xr-x 2 root root 4096 Jul 15 21:55 libdrwxr-xr-x. 2 root root 4096 Sep 23 2011 lib64drwxr-xr-x. 2 root root 4096 Sep 23 2011 libexecdrwxr-xr-x 11 www www 4096 Jul 25 16:38 nginx-1.4.3drwxr-xr-x 6 root root 4096 Jun 23 17:38 pcre-8.33drwxr-xr-x 10 root root 4096 Jul 25 21:59 proftpd-1.3.4ddrwxr-xr-x. 2 root root 4096 Sep 23 2011 sbindrwxr-xr-x. 5 root root 4096 May 12 2013 sharedrwxr-xr-x. 3 root root 4096 May 13 2013 srcdrwxr-xr-x 5 zabbix zabbix 4096 Jun 20 17:56 zabbixdrwxr-xr-x 6 zabbix zabbix 4096 Aug 4 10:28 zabbix_proxy[email protected]:/usr/local06:07:14 # ruby -v-bash: /usr/bin/ruby: No such file or directory[email protected]:/usr/local06:07:16 # gem -v-bash: /usr/bin/gem: No such file or directory[email protected]:/usr/local06:07:18 # bundle -v-bash: /usr/bin/bundle: No such file or directory
If you want to use my example, you can download it from GitHub (the address is https://github.com/dl528888/ansible-examples/tree/master/ruby_install) and put it in the/etc/ansible directory. below is the content
This article is from the "Yin-Technical Exchange" blog, please be sure to keep this source http://dl528888.blog.51cto.com/2382721/1535724