使用terraform在AWS中部署相当大的基础架构时,我们的遥控器tfstate已损坏并被删除.
从文档中,我收集到terraform refresh应该查询AWS以获取基础结构的真实状态并按顺序更新tfstate,但这不会发生:我的tfstate未受影响而plan + apply会产生很多Already existing错误.
什么是terraform refresh真的?
我正在解析gitlab api的curl输出,我需要在查询中添加sort_by,然后仅选择某些值。
样本输入:
[
{
"id": 10,
"name": "another-test",
"path": "another-test",
"description": "",
"visibility": "private",
"lfs_enabled": true,
"avatar_url": null,
"web_url": "https://mygitlab/groups/another-test",
"request_access_enabled": false,
"full_name": "another-test",
"full_path": "another-test",
"parent_id": 9
},
{
"id": 11,
"name": "asdfg",
"path": "asdfg",
"description": "",
"visibility": "private",
"lfs_enabled": true,
"avatar_url": null,
"web_url": "https://mygitlab/groups/asdfg",
"request_access_enabled": false,
"full_name": "asdfg",
"full_path": "asdfg",
"parent_id": 7
}
Run Code Online (Sandbox Code Playgroud)
我用jq解析JSON,如下所示:
curl http://..... | jq -r '.[] | select(.parent_id!=null) | .name, .parent_id'
Run Code Online (Sandbox Code Playgroud)
这完全按预期工作,但是当我尝试按parent_id对结果进行排序时,出现错误:
curl http://..... | jq -r '.[] | select(.parent_id!=null) | .name, .parent_id …Run Code Online (Sandbox Code Playgroud) 我需要在python中操作几个列表,我需要每个列表中包含它包含的第三个值的名称,但是我无法解决这个问题的语法.
谢谢
编辑:
我正在为nagios编写一个插件,它从mssql服务器中提取数据,我需要格式化nagios perfdata的数据.我已经完成了大部分工作,我只需要格式化数据.
def main():
parser = optparse.OptionParser(usage=usage)
parser.add_option("-H", "--host", dest="host", help="hostname or ip address to check", default="localhost")
parser.add_option("-u", "--user", help="DB username", type="string")
parser.add_option("-p", "--password", help="DB password")
parser.add_option("-P", "--port", help="database port", default="1433")
parser.add_option("-d", "--database", help="Database to query")
(options, args) = parser.parse_args()
con_string = "DRIVER=FreeTDS;SERVER={0};PORT={1};UID={2};PWD={3};DATABASE={4}" . format(options.host,options.port,options.user,options.password,options.database)
try:
con = pyodbc.connect(con_string)
except:
print "CRITICAL: error connecting, wrong options or database may be down"
print sys.exc_info()
exit(2) # crtical
# if we are connected, let's fetch some data!
cur = …Run Code Online (Sandbox Code Playgroud) 我有一个散列哈希,我需要访问一个值,如果相同的子哈希值匹配字符串.
这是我试图访问的哈希的一部分:
{
'ACCOUNTINFO' => {
'ENTRY' => [
{
'Name' => 'fields_12'
},
{
'Name' => 'fields_24'
},
{
'content' => 'Piso 12',
'Name' => 'TAG'
},
{
'Name' => 'fields_23'
},
]
}
}
Run Code Online (Sandbox Code Playgroud)
如果Name是"Tag",我需要"content"的值.
我可以访问姓名:
$name = $refia->{ACCOUNTINFO}{ENTRY}{Name};
Run Code Online (Sandbox Code Playgroud)
但我找不到任何方式来在需要时访问内容.
我得到了这个:
if ($refia->{ACCOUNTINFO}{ENTRY}{Name} eq "TAG") {
###
}
Run Code Online (Sandbox Code Playgroud)
谢谢
我试图在perl脚本中使用stat().我已经阅读了关于perldocs的文档,说如何使用它:
$mode = (stat($filename))[2];
Run Code Online (Sandbox Code Playgroud)
但这不起作用:
$mode = (stat($filename))[2];
print $mode;
Use of uninitialized value $mode in print at ...
Run Code Online (Sandbox Code Playgroud)
我认为需要另一种语法来访问stat返回的值.Data :: dumper返回此结构:
@stat = stat($filename);
print Dumper(@stat);
$VAR1 = bless( [
48,
305368,
33188,
1,
0,
0,
0,
'2011',
1397569653,
1397569653,
1397569653,
4096,
8
], 'File::stat' );
Run Code Online (Sandbox Code Playgroud) 在perl中:
if (!$var) { $var = 24 }
Run Code Online (Sandbox Code Playgroud)
并且:
if (!$var) { $var = 24; }
Run Code Online (Sandbox Code Playgroud)
是正确的,当我期望只有第二个工作.
哪一个是最习惯的语法?