0

So I have been scratching my head and I think the solution is easy but can not see the light :-)

I have this code which reads the registry and gets the MSSQL names:

- name: check for instances
   win_reg_stat:
     path: HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server
   register: instance_output

I then get the services running for them:

- name: get the services
   ansible.windows.win_service_info:
     name: MSSQL*
   register: service_output
   failed_when: service_output is not defined

in my debug i am joining the 2 sets:

- name: debug
   debug: 
     msg:
       - "{{ item }}"
   loop:
     - "{{ instance_output.properties.InstalledInstances.value | zip (service_output| json_query('services[*].start_mode')) | list }}"

and i get the data:

[
   [
     "db1",
     "manual"
   ],
   [
     "db2",
     "auto"
   ],
   [
     "db3",
     "disabled"
   ]
 ]

The number of dbs can be anything, so I can not use item.0, item.1, and item.2

My question is this ... how can set up a when clause where start_mode is not disabled?

I have tried with_items, however I am using ansible 2.15.3 so I know sooner or later with_items will not work...

I have tried flatten,

but I am essentially trying to get the return of db1 and db2 to continue the next part of the tasks.

Here is a snippet of one service_output

{
                    "checkpoint": 0,
                    "controls_accepted": [
                        "stop",
                        "pause_continue",
                        "shutdown"
                    ],
                    "dependencies": [],
                    "dependency_of": [
                        "SQLAgent$db1"
                    ],
                    "description": "",
                    "desktop_interact": false,
                    "display_name": "db1",
                    "error_control": "normal",
                    "failure_actions": [],
                    "failure_actions_on_non_crash_failure": false,
                    "failure_command": null,
                    "failure_reboot_msg": null,
                    "failure_reset_period_sec": 0,
                    "launch_protection": "",
                    "load_order_group": "",
                    "name": "MSSQL$db1",
                    "path": "\"D:\\",
                    "pre_shutdown_timeout_ms": 1,
                    "preferred_node": null,
                    "process_id": 4300,
                    "required_privileges": [],
                    "service_exit_code": 0,
                    "service_flags": [],
                    "service_type": "",
                    "sid_info": "",
                    "start_mode": "manual",
                    "state": "",
                    "triggers": [],
                    "username": "",
                    "wait_hint_ms": 0,
                    "win32_exit_code": 0
                }
2
  • Can you provide an example of your service_output so one could have a look into a solution with map or sellectattr? Commented Feb 21, 2024 at 17:15
  • Hi @U880D I have added a snippet from the service_output (only db1). Thanks Commented Feb 21, 2024 at 18:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.