json-query

json format query with contains

别来无恙 提交于 2019-12-11 18:15:03
问题 I have the following json output in ansible: [{ "active_transaction": null, "cores": 4, "hostname": "alpha-auth-wb01" }, { "active_transaction": null, "cores": 4, "hostname": "beta-auth-wb01" }] Now I am trying to filter the output to just show the output where the hostname contains alpha for example. Output should be: [{ "active_transaction": null, "cores": 4, "hostname": "alpha-auth-wb01" }] Code and results: Ansible code jq: "[?contains(hostname, 'alpha')]" fatal: [worker.domain]: FAILED!

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

JMESpath expression to filter object by property and return list of object names having this property set

喜夏-厌秋 提交于 2019-12-11 00:43:37
问题 Is it possible to write JMESPath expression to return a list of object names where a specific subproperty value is set? In the example below I'd like to get a list of all hostsnames where fileexists.stat.exists is set to true. My goal is to use Ansible hostvars structure to get a list of all hosts where a specific file is present. { "hostvars": { "oclab1n01.example.org": { "fileexists": { "changed": false, "failed": false, "stat": { "exists": false } } }, "oclab1n02.example.org": {

Delete an object from nested array in openjson SQL Server 2016

久未见 提交于 2019-12-07 15:10:22
问题 I want to delete the "AttributeName" : "Manufacturer" from the below json in SQL Server 2016: declare @json nvarchar(max) = '[{"Type":"G","GroupBy":[], "Attributes":[{"AttributeName":"Class Designation / Compressive Strength"},{"AttributeName":"Size"},{"AttributeName":"Manufacturer"}]}]' This is the query I tried which is not working select JSON_MODIFY(( select JSON_Query(@json, '$[0].Attributes') as res),'$.AttributeName.Manufacturer', null) 回答1: Here is the working solution using the for

ansible json-query path to select item by content

匆匆过客 提交于 2019-12-07 04:12:42
问题 Does anyone know what json-query filter can be used to select Tigger's food in the sample JSON below? The JSON is a simplified stand-in for a massive and relatively complicated AWS blob. Some background: I was rather pleased to discover that Ansible has a json-query filter. Given that I was trying to select an element from an AWS JSON blob this looked as if it was just what I needed. However I quickly ran into trouble because the AWS objects have tags and I needed to select items by tag. I

MySQL nested JSON column search and extract sub JSON

回眸只為那壹抹淺笑 提交于 2019-12-06 22:29:15
问题 I have a MySQL table authors with columns id , name and published_books . In this, published_books is a JSON column. With sample data, id | name | published_books ----------------------------------------------------------------------- 1 | Tina | { | | "17e9bf8f": { | | "name": "Book 1", | | "tags": [ | | "self Help", | | "Social" | | ], | | "language": "English", | | "release_date": "2017-05-01" | | }, | | "8e8b2470": { | | "name": "Book 2", | | "tags": [ | | "Inspirational" | | ], | |

ansible json-query path to select item by content

橙三吉。 提交于 2019-12-05 09:01:19
Does anyone know what json-query filter can be used to select Tigger's food in the sample JSON below? The JSON is a simplified stand-in for a massive and relatively complicated AWS blob. Some background: I was rather pleased to discover that Ansible has a json-query filter. Given that I was trying to select an element from an AWS JSON blob this looked as if it was just what I needed. However I quickly ran into trouble because the AWS objects have tags and I needed to select items by tag. I tried selector paths equivalent to Foods[Tags[(Key='For') & (Value='Tigger')]] and similar but didn't

MySQL nested JSON column search and extract sub JSON

两盒软妹~` 提交于 2019-12-05 03:27:20
I have a MySQL table authors with columns id , name and published_books . In this, published_books is a JSON column. With sample data, id | name | published_books ----------------------------------------------------------------------- 1 | Tina | { | | "17e9bf8f": { | | "name": "Book 1", | | "tags": [ | | "self Help", | | "Social" | | ], | | "language": "English", | | "release_date": "2017-05-01" | | }, | | "8e8b2470": { | | "name": "Book 2", | | "tags": [ | | "Inspirational" | | ], | | "language": "English", | | "release_date": "2017-05-01" | | } | | } -----------------------------------------

How to search SQL column containing JSON array

时光怂恿深爱的人放手 提交于 2019-11-28 12:20:27
I have a SQL column that has a single JSON array: {"names":["Joe","Fred","Sue"]} Given a search string, how can I use SQL to search for a match in the names array? I am using SQL 2016 and have looked at JSON_QUERY, but don't know how to search for a match on a JSON array. Something like below would be nice. SELECT * FROM table WHERE JSON_QUERY(column, '$.names') = 'Joe' Serkan Arslan For doing a search in a JSON array, one needs to use OPENJSON DECLARE @table TABLE (Col NVARCHAR(MAX)) INSERT INTO @table VALUES ('{"names":["Joe","Fred","Sue"]}') SELECT * FROM @table WHERE 'Joe' IN ( SELECT