*Hello,*
*        I am new to this group and ansible as well.  I would like to skill 
up and be able to perform config management tasks using Ansible playbooks.  
The current problem I am working on is to be able to validate KIE server 
deployment.  I made little progress by checking your group and other blogs 
but stuck with this error below.  Please help if you can identify the issue 
right away or if you could guide me where to look for validating rest api's 
using ansible.  *

*// ------------------------------  ERROR MESSAGE  
-----------------------------------*

********************
fatal: [localhost]: FAILED! => {"msg": "The conditional check 
'results.content is search(\"SUCCESS\")' failed. The error was: error while 
evaluating conditional (results.content is search(\"SUCCESS\")): 'dict 
object' has no attribute 'content'"}

// --------------------- YAML -------------------------------


























*- name: Validate KIE Server deployment  hosts: localhost  vars:    
kie_server_host: "https://apiurl.com";    kie_server_port: "13001"    
kieserver_user: "user"    kieserver_password: "somepassword"    
expected_server_version: "7.72.0.Final"  tasks:    - name: Get KIE Server 
information      uri:        url: "http://{{ kie_server_host }}:{{ 
kie_server_port }}/kie-server/services/rest/server/"        user: "{{ 
kieserver_user }}"        password: "{{ kieserver_password }}"        
return_content: yes        method: GET      register: results    - name: 
Check server version      assert:        that: results.content is 
search("SUCCESS")    - debug:       var: results*

*                                       Here it goes:*

*When I do a dry run of the playbook I see following results  --- saying 
that ansible.legacy.uri does not support check mode*

$ ansible-playbook newapicall.yml -C
[WARNING]: provided hosts list is empty, only localhost is available. Note 
that the implicit localhost does not match 'all'

PLAY [Validate KIE Server deployment] 
*****************************************************************************************************

TASK [Gathering Facts] 
********************************************************************************************************************
ok: [localhost]

TASK [Get KIE Server information] 
*********************************************************************************************************
skipping: [localhost]

TASK [debug] 
******************************************************************************************************************************
ok: [localhost] => {
    "results": {
        "changed": false,
        "failed": false,
        "msg": "remote module (ansible.legacy.uri) does not support check 
mode",
        "skipped": true
    }
}

PLAY RECAP 
********************************************************************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0 
   skipped=1    rescued=0    ignored=0


*But when I finally run the play book - Debug of VAR = results returns 
content from KIE server that I need to use to parse information like if 
"SUCCESS" is seen in content then deployment was successful e.g.*





*// ------------------ check ----------------------    - name: Check server 
version      assert:        that: results.content is search("SUCCESS")// 
-----------------------------------------------*



$ ansible-playbook newapicall.yml
[WARNING]: provided hosts list is empty, only localhost is available. Note 
that the implicit localhost does not match 'all'

PLAY [Validate KIE Server deployment] 
*****************************************************************************************************

TASK [Gathering Facts] 
********************************************************************************************************************
ok: [localhost]

TASK [Get KIE Server information] 
*********************************************************************************************************
ok: [localhost]

TASK [debug] 
******************************************************************************************************************************
ok: [localhost] => {
    "results": {
        "changed": false,
        "connection": "close",
        "content": "<?xml version=\"1.0\" encoding=\"UTF-8\" 
standalone=\"yes\"?>\n<response type=\"SUCCESS\" msg=\"Kie Server info\">\n 
   <kie-server-info>\n        <capabilities>KieServer</capabilities>\n     
   <capabilities>BRM</capabilities>\n       
 <capabilities>BPM</capabilities>\n       
 <capabilities>CaseMgmt</capabilities>\n       
 <capabilities>BPM-UI</capabilities>\n       
 <capabilities>BRP</capabilities>\n       
 <capabilities>DMN</capabilities>\n       
 <capabilities>Swagger</capabilities>\n       
 
<location>https://apiurl.com:11001/kie-server/services/rest/server</location>\n 
       <messages>\n            <content>Server 
KieServerInfo{serverId='kie-weblogic-qa1', version='7.72.0.Final', 
name='kie-weblogic-qa1', 
location='https://apiurl.com:11001/kie-server/services/rest/server', 
capabilities=[KieServer, BRM, BPM, CaseMgmt, BPM-UI, BRP, DMN, Swagger]', 
messages=null', mode=DEVELOPMENT}started successfully at Tue Jan 24 
20:56:01 UTC 2023</content>\n            <severity>INFO</severity>\n       
     <timestamp>2023-01-24T20:56:01.597Z</timestamp>\n        </messages>\n 
       <mode>DEVELOPMENT</mode>\n        <name>kie-weblogic-qa1</name>\n   
     <id>kie-weblogic-qa1</id>\n        <version>7.72.0.Final</version>\n   
 </kie-server-info>\n</response>\n",
        "content_length": "1252",
        "content_type": "application/xml",
        "cookies": {
            "JSESSIONID": 
"xHRmZgYJkoG2J89BjT66_01TEr_-Zb0wJx1sPnfsxTH8lCz1Tzyv!1154788022"
        },
        "cookies_string": 
"JSESSIONID=xHRmZgYJkoG2J89BjT66_01TEr_-Zb0wJr1SPnfsxTH8lwcz1Tyv!1154788022",
        "date": "Sat, 18 Feb 2023 21:20:07 GMT",
        "elapsed": 0,
        "failed": false,
        "msg": "OK (1252 bytes)",
        "redirected": false,
        "set_cookie": 
"JSESSIONID=xHRmZgqG2J89BjT66_01TEr_-Zb0wJx1rSPnfsxTH8lwCz1Tyv!1154788022; 
path=/; HttpOnly",
        "status": 200,
        "url": "https://apiurl.com:11001/kie-server/services/rest/server/";
    }
}

PLAY RECAP 
********************************************************************************************************************************
localhost                  : ok=3    changed=0    unreachable=0    failed=0 
   skipped=0    rescued=0    ignored=0


playbook: newapicall.yml
$ ansible-playbook newapicall.yml -C
[WARNING]: provided hosts list is empty, only localhost is available. Note 
that the implicit localhost does not match 'all'

PLAY [Validate KIE Server deployment] 
*****************************************************************************************************

TASK [Gathering Facts] 
********************************************************************************************************************
ok: [localhost]

TASK [Get KIE Server information] 
*********************************************************************************************************
skipping: [localhost]

TASK [Check server vresion] 
***************************************************************************************************************
fatal: [localhost]: FAILED! => {"msg": "The conditional check 
'results.content is search(\"SUCCESS\")' failed. The error was: error while 
evaluating conditional (results.content is search(\"SUCCESS\")): 'dict 
object' has no attribute 'content'"}

PLAY RECAP 
********************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1 
   skipped=1    rescued=0    ignored=0


*Below is the full playbook with some information removed for security. 
 But wen I check for server version or if check for content showing 
"SUCCESS"  when "status": 200 or even if the kie server deployment was 
successful with given containers would be useful information.*










*e.g.#         that:#          - results.status == 200#    - 
"results.json.version" == "{{ expected_server_version }}"e.g.when kie 
server returns containre information to be parsed"content": "<?xml 
version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<response 
type=\"SUCCESS\" msg=\"List of created containers\">\n   
 <kie-containers>\n  *



Thank you in advance -- I have put my comments in italics and code in BOLD 
to separate the output from debug and my comments.  I think I may have 
mixed up in content format expectations, it is returning in xml and code 
expects json. ?? or may be more issues.

Regards
Sohail Jaffer

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/f8bd8b32-8390-4baa-8b27-8fb79e559ec5n%40googlegroups.com.

Reply via email to