我正在尝试从 Ansible stdout_lines 结果中过滤掉一行。我运行的 ansible playbook 任务是以下 shell 参数:
- name: VERIFY | Confirm that queue exists properly
shell: aws sqs list-queues --region {{region}}
environment: "{{ aws_cli_environment|d({}) }}"
register: sqs_list
Run Code Online (Sandbox Code Playgroud)
为了查看结果,我进行了调试:
- debug:
msg: "{{ sqs_list.stdout_lines|list }}"
Run Code Online (Sandbox Code Playgroud)
在剧本运行期间给出以下结果:
TASK [sqs : debug] ********************************************************************************************************************************************************************************************
ok: [localhost] => {
"msg": [
"{",
" \"QueueUrls\": [",
" \"sampleurl1\",",
" \"sampleurl2\",",
" \"sampleurl3\",",
" \"sampleurl4\",",
" \"https://sampleurl5/test_sqs\"",
" ]",
"}"
]
}
Run Code Online (Sandbox Code Playgroud)
我只希望最后一个 url,“test_sqs”出现在“msg”: 下,我尝试了以下过滤器,但没有运气:
- name: VERIFY | Find SQS url
command: …Run Code Online (Sandbox Code Playgroud) 我发现 AWS Cost Explorer 控制台和 AWS CLI Cost Explorer 给出了两个不同的数字。有什么原因导致这种情况发生吗?
例如:从我的控制台,您可以看到我的 Cloudtrail 总额为 72.66 美元
然而,当我将这些相同的精确指标用于 CLI 时,我的总计为 72.04 美元
我知道这看起来没什么大区别,我只是以 Cloudtrail 为例,但我的一些价格较高的服务有更大的差异。出现这种情况是否有原因/是否可以采取措施使控制台和 CLI 具有匹配的每月成本?
我有一个ROOT_MODULEmain.tf:
#Root Module - Just run the script
resource "null_resource" "example" {
provisioner "local_exec" {
command = "./script.sh"
}
Run Code Online (Sandbox Code Playgroud)
和script.sh:
echo "Hello world
Run Code Online (Sandbox Code Playgroud)
现在我在其他地方有另一个目录,我用另一个目录创建了一个CHILD_MODULEmain.tf:
#Child Module
module "ROOT_MODULE" {
source = "gitlabURL/ROOT_MODULE"
}
Run Code Online (Sandbox Code Playgroud)
我已经导出了我的计划文件: terraform plan -out="planfile"
但是,当我terraform apply针对计划文件执行此操作时,我当前所在的目录不再知道 script.sh 在哪里。我需要将脚本保存在与根模块相同的目录中。该脚本也在 gitlab 存储库中,因此我没有本地路径来调用它。知道如何将此脚本放入我的子模块/从我的计划文件中执行它吗?
Error running command './script.sh': exit status 1. Output: cannot access 'script.sh': No such file or directory
Run Code Online (Sandbox Code Playgroud) 我有一个映射变量来标识现有的 s3 存储桶:
resource "aws_s3_bucket" "bucket" {
for_each = var.s3_replication
bucket = each.value.source
#other configuration
}
variable "s3_replication" {
description = "Map of buckets to replicate"
type = map
default = {
logs = {
source = "logs_bucket",
destination = "central_logs_bucket"
},
security = {
source = "cloudtrail_bucket",
destination = "central_security_bucket"
}
}
}
Run Code Online (Sandbox Code Playgroud)
由于这些存储桶已经存在,我正在尝试导入它们,然后将配置应用于它们以更新资源。不幸的是,我无法弄清楚如何对这些进行地形导入。我试过了:
terraform import aws_s3_bucket.bucket["logs"] logs_bucket
terraform import aws_s3_bucket.bucket[logs] logs_bucket
terraform import aws_s3_bucket.bucket[0] logs_bucket
terraform import aws_s3_bucket.bucket[0].source logs_bucket
terraform import aws_s3_bucket.bucket[0[source]] logs_bucket
Run Code Online (Sandbox Code Playgroud)
全部失败并出现不同的错误。关于如何导入地图上列出的现有资源有什么想法吗?
dictionary amazon-s3 amazon-web-services terraform terraform-provider-aws
我在 C# 中创建了一个字典,每个键有多个值:
编辑:根据评论的建议,结构已得到纠正:
var exampleDictionary = new Dictionary<string, Dictionary<string, double>>()
{
{
"Apple",
new Dictionary<string, double>
{
{ "Weight", 82 },
{"Size", 10},
{ "Number", 32 }
}
},
{
"Orange",
new Dictionary<string, double>
{
{ "Weight", 73 },
{"Size", 9},
{ "Number", 63 }
}
},
};
Run Code Online (Sandbox Code Playgroud)
有没有办法可以按特定值对字典键进行排序。例如,如果我想按降序按“数字”值排序,那么字典将先有橙色,然后是苹果。