jmespath

Using JMESPath and aws ec2 describe instances to output multiple tag values

牧云@^-^@ 提交于 2020-01-17 07:04:42
问题 I'm trying to output multiple tags from an ec2 instances description. The tag values that I want are Name and aws:autoscaling:groupName. "Tags": [ { "Value": "somename", "Key": "Name" }, { "Value": "some-asg-name", "Key": "aws:autoscaling:groupName" }, { "Value": "somethingelse", "Key": "project" } ], Here's what I have so far: aws ec2 describe-instances --instance-ids i-12345678 --query 'Reservations[].Instances[].[Tags[? contains(`["aws:autoscaling:groupName","Name"]`, Key)] | [0].Value,[1]

AWS RDS: how to get latest snapshot with boto3 and jmespath?

ⅰ亾dé卋堺 提交于 2020-01-05 02:33:06
问题 Here is what I tried: #!/usr/bin/env python3 import boto3 import jmespath from datetime import datetime, timedelta now = datetime.utcnow() yesterday = now - timedelta(days=1) boto3.setup_default_session(profile_name='profilename') rds_client = boto3.client('rds') response = rds_client.describe_db_snapshots(DBInstanceIdentifier='instanseid') snaplist=jmespath.search("DBSnapshots[?SnapshotCreateTime >`2016-10-24 06:11:30`].[DBSnapshotIdentifier]", response) print(snaplist) What I get is:

Filter object by property and select with key in jmespath

我是研究僧i 提交于 2019-12-28 13:50:27
问题 I'm trying to filter properties of an object in jmespath based on the value of a subproperty and want to include only those properties where the subproperty is set to a specific value. Based on this example data: { "a": { "feature": { "enabled": true, } }, "b": { }, "c": { "feature": { "enabled": false } } } I'd like to get an object with all properties where the feature is enabled. { "a": { "feature": { "enabled": true, } } } I figured I could use this jmespath query to filter the objects

Extract nested element value from JSON object using JMESPath

删除回忆录丶 提交于 2019-12-25 00:46:08
问题 I am trying to extract and transform elements from a JSON document using JMESPath . Here is my test JSON array: const search = jmespath.search; const testData = { "ServiceAccount": [ { "Type": "WIDGET", "ID": [ { "OrderNum": "12345", "OrderTyp": "ABDCD" } ] } ] }; I am trying to extract the value of the OrderNum key using the following JMESPath expression, but it returns null . Here is my search expression: const result = search(testData, 'ServiceAccount.ID.OrderNum'); console.log(result);

Sort by date with jmespath

筅森魡賤 提交于 2019-12-23 08:13:08
问题 With a json output like : { "Functions":[ { "CodeSha256":"7NBvXXacp9x3aK3cKaI=", "FunctionName":"function_1", "FunctionArn":"arn:aws:lambda:eu-west-1:1111:function:function_1", "LastModified":"2015-02-09T11:35:31.084+0000" }, { "CodeSha256":"7NBvXXacKaI=", "FunctionName":"function_3", "FunctionArn":"arn:aws:lambda:eu-west-1:1111:function:function_3", "LastModified":"2015-03-09T11:35:31.084+0000" }, { "CodeSha256":"7NBvXXacaK3cKaI=", "FunctionName":"function_2", "FunctionArn":"arn:aws:lambda

Sort by date with jmespath

隐身守侯 提交于 2019-12-23 08:11:32
问题 With a json output like : { "Functions":[ { "CodeSha256":"7NBvXXacp9x3aK3cKaI=", "FunctionName":"function_1", "FunctionArn":"arn:aws:lambda:eu-west-1:1111:function:function_1", "LastModified":"2015-02-09T11:35:31.084+0000" }, { "CodeSha256":"7NBvXXacKaI=", "FunctionName":"function_3", "FunctionArn":"arn:aws:lambda:eu-west-1:1111:function:function_3", "LastModified":"2015-03-09T11:35:31.084+0000" }, { "CodeSha256":"7NBvXXacaK3cKaI=", "FunctionName":"function_2", "FunctionArn":"arn:aws:lambda

JMESPath - Joining items in a nested array

ⅰ亾dé卋堺 提交于 2019-12-14 02:02:14
问题 I have a JSON { "key": "processId-29231", "fields": { "attachment": [ { "id": "79572", "filename": "File1.png" }, { "id": "74620", "filename": "File2.docx" }, { "id": "79072", "filename": "File3.xlsx" } ] } } I need to restructure it to this { "processId": "processId-29231", "attachments": [ "https://example.com/files/79572/File1.png", "https://example.com/files/79572/File2.docx", "https://example.com/files/79572/File1.xlsx", ] } I could make this work with a specific array index {processID

ansible filter with json_query

爷,独闯天下 提交于 2019-12-12 05:28:50
问题 I write this: - name: test for seed debug: var: hostvars|json_query("*.ansible_host") And it prints every host. But this does not filter hosts: - name: test for seed debug: var: hostvars|json_query("*[?ansible_host=='192.168.56.101']") It just prints an empty list, while I'm sure this host exists. This is the relevant inventory line: [build-servers] build-server ansible_host=192.168.56.101 Am I doing something wrong? 回答1: You should filter resulting list, not original hash: * | [?ansible_host

ansible json filter list

∥☆過路亽.° 提交于 2019-12-11 17:25:06
问题 I'm trying to filter out running services from the output of scan_services module (or service_facts in >= 2.5). The output of this module is something like this: "ansible_facts": { "services": { "NetworkManager-dispatcher.service": { "name": "NetworkManager-dispatcher.service", "source": "systemd", "state": "running" }, "NetworkManager-wait-online.service": { "name": "NetworkManager-wait-online.service", "source": "systemd", "state": "stopped" }, "NetworkManager.service": { "name":

Filtering addresses matching condition

笑着哭i 提交于 2019-12-11 17:01:31
问题 I want to provide list of allowed VLAN's as a variable to my server. Ansible playbook should be able to filter server's IP addreses based on this VLAN's. I have a list of all IP addresses available on server ( ansible_all_ipv4_addresses from ansible facts) I have a global variable my_subnets : my_subnets: - vlan: 2 subnet: "192.168.2.0/24" gateway: "192.168.2.10" - vlan: 3 subnet: "192.168.3.0/24" dns: "192.168.3.12" - vlan: 4 subnet: "192.168.4.0/24" - vlan: 5 subnet: "192.168.5.0/24" And I