私はWebサービスに対して少数のテストケースを実行するためにAnsibleを使用しています。 「コンテンツの花の括弧外のデータがある場合、私は別のタスクを実行したい、今すぐデバッグ出力に基づく可能なタスク
ok: [localhost] => {
"results": {
"access_control_allow_origin": "*",
"cache_control": "max-age=864000, private",
"changed": false,
"connection": "close",
"content": "\r\n{\"id\":1,\"deleted\":false,\"first-name\":\"xxx\",\"last-name\":\"xxx\",\"name\":\"xxx\",\"title\":\"xxx\",\"background\":\"\",\"company-id\":xx,\"company-name\":\"example\",\"company-type-id\":2,\"company-type-name\":\"Customer\",\"email-address-work\":\"[email protected]\",\"email-address-personal\":\"\",\"email-address-alternate\":\"\",\"email-address-other\":\"\",\"phone-number-work\":\1234567890\",\"phone-number-home\":\"\",\"phone-number-mobile\":\"252654789\",\"phone-number-alternate\":\"256471235\",\"business-street\":\"526574, usa\",\"business-city\":\"San Antonio\",\"business-state\":\"TX\",\"business-zip\":\"1234607\",\"business-country\":\"United States\",\"home-street\":\"\",\"home-city\":\"\",\"home-state\":\"\",\"home-zip\":\"\",\"home-country\":\"\",\"created-time\":\"2015-11-03T20:56:33.000Z\",\"last-modified-time\":\"2017-11-21T06:27:55.000Z\",\"tags\":[]}",
"content_length": "857",
"content_type": "application/json",
"date": "Tue, 21 Nov 2017 09:59:34 GMT",
"expires": "Fri, 01 Dec 2017 09:59:34 GMT",
:以下は、私の脚本です:脚本上記
- hosts: localhost
connection: local
tasks:
- name: Testing the API...
uri:
url: https://api.example.com/v1/
method: GET
user: username
password: password
status_code: 200
return_content: yes
force_basic_auth: yes
register: results
- debug: var=results
が正常に動作し、次の出力を返します。 ' セクション。上記の出力では、'content": "\r\n{\"id\":1,\"deleted...'
で始まります。どのように私はこれを達成することができますか?
したがって、最初の文字が '{'でなければ 'true'と評価される条件を書く方法を尋ねます。 – techraf
はい、あなたは正しいです – Techie
これはあなたが必要とするものですか? – techraf