rex 指定机器和组运行

指定机器运行:

task "getip", sub {
   my $output = run "ifconfig -a";
   say $output;
};

[root@node01 my-first-rex-project]# rex -H 192.168.137.3 getip
[2019-06-15 08:25:39] INFO - Running task getip on 192.168.137.3
ddad2313
$VAR1 = {
          'auto_die' => undef
        };
eth1      Link encap:Ethernet  HWaddr 00:0C:29:E0:1E:70  
          inet addr:192.168.137.3  Bcast:192.168.137.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fee0:1e70/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:112646 errors:0 dropped:0 overruns:0 frame:0
          TX packets:440836 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:11346874 (10.8 MiB)  TX bytes:59315258 (56.5 MiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:337757 errors:0 dropped:0 overruns:0 frame:0
          TX packets:337757 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:29925829 (28.5 MiB)  TX bytes:29925829 (28.5 MiB)

[2019-06-15 08:25:39] INFO - All tasks successful on all hosts




指定组运行:


[root@node01 my-first-rex-project]# cat Rexfile
use Rex -feature => ['1.3'];


group myservers => "192.168.137.2", "192.168.137.3", "myfileserver";
group myserver01 => "192.168.137.2", "192.168.137.3", "myfileserver";

desc "Get the uptime of all servers";
task "hostname", group => "myservers", sub {
   my $output = run "hostname";
   say $output;
};


task "getip", sub {
   my $output = run "ifconfig -a";
   say $output;
};
desc "Start httpd Service";
task "start_httpd", group => "myservers", sub {
    service "httpd" => "restart";
};

[root@node01 my-first-rex-project]# rex -g myserver01 getip
[2019-06-15 08:26:44] INFO - Running task getip on 192.168.137.2
ddad2313
$VAR1 = {
          'auto_die' => undef
        };
eth0      Link encap:Ethernet  HWaddr 00:0C:29:29:8E:AC  
          inet addr:192.168.137.2  Bcast:192.168.137.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe29:8eac/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:7965 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7694 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:690415 (674.2 KiB)  TX bytes:688876 (672.7 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:1057 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1057 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:153310 (149.7 KiB)  TX bytes:153310 (149.7 KiB)

[2019-06-15 08:26:45] INFO - Running task getip on 192.168.137.3
ddad2313
$VAR1 = {
          'auto_die' => undef
        };
eth1      Link encap:Ethernet  HWaddr 00:0C:29:E0:1E:70  
          inet addr:192.168.137.3  Bcast:192.168.137.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fee0:1e70/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:112768 errors:0 dropped:0 overruns:0 frame:0
          TX packets:440961 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:11359020 (10.8 MiB)  TX bytes:59329185 (56.5 MiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:337757 errors:0 dropped:0 overruns:0 frame:0
          TX packets:337757 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:29925829 (28.5 MiB)  TX bytes:29925829 (28.5 MiB)

[2019-06-15 08:26:46] INFO - Running task getip on myfileserver
原文地址:https://www.cnblogs.com/hzcya1995/p/13348711.html