Func : CommandModule を利用する2016/09/29 |
|
CommandModule の利用方法です。様々なモジュールが用意されていますが、実質ほとんどの操作はこのモジュールで実行可能です。
前述の yum install ~ もこちらで実行できます。基本的には以下のような書式で自由にコマンドを発行することができます。
⇒ func target call command run "command"
|
|
| [1] | 全 Minion で wget をインストールする。 ( 表示結果を見易くするため、全て「sed 's/\\n/\n/g'」につなげています ) |
|
[root@dlp ~]# func "*" call command run "yum -y install wget" | sed 's/\\n/\n/g'
('node01.srv.world',
[0,
'Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.riken.jp
* extras: ftp.riken.jp
* updates: ftp.riken.jp
Resolving Dependencies
--> Running transaction check
---> Package wget.x86_64 0:1.14-10.el7_0.1 will be installed
--> Finished Dependency Resolution
.....
.....
Installed:
wget.x86_64 0:1.14-10.el7_0.1
Complete!
',
''])
('dlp.srv.world',
[0,
'Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.riken.jp
* extras: ftp.riken.jp
* updates: ftp.riken.jp
Resolving Dependencies
--> Running transaction check
---> Package wget.x86_64 0:1.14-10.el7_0.1 will be installed
--> Finished Dependency Resolution
.....
.....
Installed:
wget.x86_64 0:1.14-10.el7_0.1
Complete!
',
''])
|
| [2] | 全 Minion の /home を ls する。 |
|
[root@dlp ~]# func "*" call command run "ls -l /home" | sed 's/\\n/\n/g'
('node01.srv.world',
[0,
'total 4
drwx------. 2 cent cent 59 Aug 8 2015 cent
-rw-r--r--. 1 root root 10 Sep 30 16:46 test.txt
',
''])
('dlp.srv.world',
[0,
'total 4
drwx------. 2 cent cent 59 Aug 8 2015 cent
-rw-r--r--. 1 root root 10 Sep 30 16:46 test.txt
',
''])
|
| [3] | ある Minion の /etc/passwd を cat する。 |
|
[root@dlp ~]# func "node01.srv.world" call command run "cat /etc/passwd" | sed 's/\\n/\n/g'
('node01.srv.world',
[0,
'root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
.....
.....
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
mysql:x:27:27:MariaDB Server:/var/lib/mysql:/sbin/nologin
',
''])
|
| [4] | 全 Minion で /home 配下に test.dir ディレクトリを作成する。 |
|
[root@dlp ~]# func "*" call command run "mkdir /home/test.dir" ('node01.srv.world', [0, '', '']) ('dlp.srv.world', [0, '', '']) [root@dlp ~]# func "*" call command run "ls -ld /home/test.dir" | sed 's/\\n/\n/g'
('node01.srv.world',
[0, 'drwx------. 2 root root 6 Sep 30 17:01 /home/test.dir
', ''])
('dlp.srv.world',
[0, 'drwx------. 2 root root 6 Sep 30 17:01 /home/test.dir
', ''])
|
| [5] | 全 Minion で /home 配下の test.txt の所有者を nobody にしてアクセス権を 600 にする。 |
|
[root@dlp ~]# func "*" call command run "chown nobody. /home/test.txt;chmod 600 /home/test.txt" ('node01.srv.world', [0, '', '']) ('dlp.srv.world', [0, '', '']) [root@dlp ~]# func "*" call command run "ls -l /home/test.txt" | sed 's/\\n/\n/g'
('node01.srv.world',
[0, '-rw-------. 1 nobody nobody 10 Sep 30 16:46 /home/test.txt
', ''])
('dlp.srv.world',
[0, '-rw-------. 1 nobody nobody 10 Sep 30 16:46 /home/test.txt
', ''])
|
| [6] | 全 Minion で ntpd を再起動する。 |
|
[root@dlp ~]# func "*" call command run "systemctl restart ntpd" | sed 's/\\n/\n/g' ('node01.srv.world', [0, '', '']) ('dlp.srv.world', [0, '', '']) |
| Sponsored Link |
|
|