(R)?ex 部署 & 配置管理框架

搜索

新闻

2016-03-07
(R)?ex 1.4.0 发布, 包含大量更新. 详情 发布文档.
2015-09-04
(R)?ex 1.3.3 released, fixing a bunch of bugs. See the release notes for more details.
2015-06-22
adjust GmbH is sponsoring the (R)?ex project with a new build server. Thank you for your support!
2015-06-17
(R)?ex 1.3.2 released, fixing issues related to file manipulation when run on BSDs. See the release notes for more details.
2015-06-09
Read the second part of "Rex in practice" series about Test-driven infrastructure.
2015-05-09
repositor.io 1.1.0 released. repositor.io is a repository management tool for apt, yum, yast and docker. This is a bugfix release with fixes for ubuntu and centos7 installation media mirroring.
2015-03-27
阅读 Andy Beverley 带来的演讲文稿 An introduction to Rex

会议

2015-05-07
German Perl Workshop 上做 Infrastructure as Code (ger) 的演讲。

培训

2015-11-30/2015-12-01 (Karlsruhe)

需要帮助吗?

Rex 是一个开源的项目,所以你可以找到社区的支持,连接如下:

  • IRC: #rex on freenode
  • 邮件组: rex-users
  • 问题列表: Github
  • 特性需求: 你需要什么 特性?
  • 商务支持: inovex
  • QQ群: 252744726

Professional support is also available.

Rex 需要的 Perl 基础

Perl是一种脚本语言设计让困难的事情更加的简单易行。本指南中你就可以学会足够书写自己的 Rex 任务的 Perl 知识。

如果你有什么建议和想法,请发表评论,或者在 freenode 的 #rex 频道上告诉我们,或者直接通过GitHub repository 发 pull request。

变量

标量变量

标量可以包含字符串、数字、对象、引用.

my $name = "John";    # this is a string
my $age = 28;   # this is a number (integer)
my $float = 28.5;   # also a number, but a float
my $car = Car->new();   # this is an object from the class Car

数组变量

数组列表。像一个购物清单。他们包含了很多的标量.

my @names = ("John", "Fred", "Charley");
my @to_buy = qw(Cheese Butter Salt Lemons Oranges Apples);

访问数组元素必须使用索引。索引是从零开始的:

say "First name: " . $names[0];
say "Last name: " . $name[2];
say "Also last name: " . $name[-1];

分割字符串成数组:

my $string = "John,Fred,Carl,Lewis";
my @names = split(/,/, $string);

把数组连接成一个字符串:

my @names = ("John", "Fred", "Carl", "Lewis");
my $string = join(",", @names);     # -> John,Fred,Carl,Lewis

如果你想遍历一个数组,这样做:

for my $name (@names) {
   say "Current name: $name";
}

哈希变量

hashs 比较像数组,但是它有着命名的索引,一般叫做键。

my %person = (
   name => "John",
   age  => 28,
   city => "New York"
);

访问一个hash 必须用key:

say "Name: " . $person{"name"};
say "Age: " . $person{"age"};
say "City: " . $person{"city"};

如果你遍历hash 可以这样做. 但是没有排序.

for my $key ( keys %person ) {
   say "key: $key -> value: " . $person{$key};
}

条件语句

if ( $name eq "John" ) {
   say "Hello, my name is John!";
} else {
   say "Well, my name is not John...";
}

if ( $name ne "John" ) {
   say "Yes, my name is NOT John...";
} else {
   say "Hello, my name is John!";
}

if ( $age < 30 ) {
   say "I'm younger than 30.";
} elsif ( $age >= 30 && $age <= 50 ) {
   say "Well, I'm between 30 and 50.";
} else {
   say "I'm older than 50.";
} 

循环

for my $num (1..5) {
   say "> $num";
}

# looping over an array
for my $item (@array) {
   say "> $item";
} 

正则表达式

my $name = "John";
if ( $name =~ m/john/ ) {     # will not match, because the "J" in $name is uppercase
}

if ( $name =~ m/john/i ) {    # _will_ match, because we use the "i" modifier for case-insensitive matching
}

$name =~ s/john/Fred/i;       # this will replace the first match of "john" (regardless of its case) with "Fred"
$name =~ s/john/Fred/ig;      # this will replace all matches of "john" (regardless of its case) with "Fred"

函数

sub my_function {      # define the function called "my_function"
}

sub my_function {      # define the function called "my_function" 
   my $param1 = $_[0]; # get the 1st parameter and save it in $param1
   my $param2 = $_[1]; # get the 2nd parameter and save it in $param2
   my $param3 = $_[2]; # get the 3rd parameter and save it in $param3

}

sub my_function {
   my ($param1, $param2, $param3) = @_; # the same as above
}

my_function();     # call the function "my_function"
my_function;       # also calls "my_function"
&my_function;      # also calls "my_function"
my_function("john", 28);    # call "my_function" with 2 parameters
my_function "john", 28;     # also calls "my_function" with 2 parameters: the brackets are not needed

辅助函数

打印一个列表上下文,数组,hash

use Data::Dumper;

say Dumper($scalar);
say Dumper(@array);
say Dumper(%hash);
comments powered by Disqus
Fork me on GitHub
Google Group / Twitter / GitHub / Mailinglist / irc.freenode.net #rex   -.ô.-   Disclaimer

D