假设 df 命令返回以下内容。
[john.doe@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 372607 170989 177862 50% /boot
/dev/sda2 129774 6994 122780 6% /
Run Code Online (Sandbox Code Playgroud)
借助 Ansible,我可以使用 shell 模块捕获 /dev/sda1 的可用值 (177862)。
[john.doe@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 372607 170989 177862 50% /boot
/dev/sda2 129774 6994 122780 6% /
Run Code Online (Sandbox Code Playgroud)
这将显示类型是AnsibleUnsafeText。如果我对 Gather_facts 执行相同操作,也会返回 AnsibleUnsafeText。我不知道如何使类型成为整数而不是 AnsibleUnsafeText。
TASK [standard out]
ok: [localhost] => {
"msg": "122780"
}
TASK [type]
ok: [localhost] => {
"msg": "AnsibleUnsafeText"
} …Run Code Online (Sandbox Code Playgroud) 我有以下 Perl 脚本。
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my @fruits = qw(apple banana orange pear);
print Dumper \@fruits;
foreach my $fruit (@fruits) {
$fruit =~ s|apple|peach|;
}
print Dumper \@fruits;
Run Code Online (Sandbox Code Playgroud)
返回以下内容。
$VAR1 = [
'apple',
'banana',
'orange',
'pear'
];
$VAR1 = [
'peach',
'banana',
'orange',
'pear'
];
Run Code Online (Sandbox Code Playgroud)
我不明白为什么以下行将 @fruits 数组中的 apple 更改为 peach,因为我认为此行仅适用于 $fruit 变量,而不适用于 @fruits 数组。
$fruit =~ s|apple|peach|;
Run Code Online (Sandbox Code Playgroud)