lowlydba / lowlydba.sqlserver

:spoon: A cross-platform Ansible collection using PowerShell to configure and maintain SQL Server.
https://galaxy.ansible.com/ui/repo/published/lowlydba/sqlserver
GNU General Public License v3.0
21 stars 12 forks source link

"Configuring Availability Group failed: The term 'Get-DbaAvailabilityGroup' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again."} #269

Open suganthanraj opened 1 week ago

suganthanraj commented 1 week ago

not Recognized as the name of a cmdlet I am trying configure SQAON in azure VMs. I installed dbatools in windows target machine. In the source i installed pymssql, it is the mandatory pre-req to install py packages and ps modules

To Reproduce

  1. Configure SQL Availability Group
  2. Configure SQL AG Listener

Expected behavior Once i import he ansible collection in my playbook . It should be able to create ag and ag listener. But i am facing like error as below:- fatal: [sqlnode2.accit.com]: FAILED! => {"changed": false, "msg": "Configuring Availability Group failed: The term 'Get-DbaAvailabilityGroup' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again."}

Versions(please complete the following information):

Please attached the screenshots image (15) image (4) 1 Add any other context about the problem here.

lowlydba commented 6 days ago

Configuring Availability Group failed: The term 'Get-DbaAvailabilityGroup' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again

This indicates that dbatools is not actually available on the host you're running against. Try adding some basic pwsh debug tasks to ensure that you can execute dbatools functions on the host.

Please also include your playbook and inventory sample for a MVP.

lowlydba commented 6 days ago

Its also worth noting that if you are intending to execute this on the controller, you'll need to use a connection hack (https://github.com/lowlydba/lowlydba.sqlserver/blob/main/tests/integration/targets/setup_sqlserver_test_plugins/connection_plugins/local_pwsh.py) like we do in the testing pipelines in order to get pwsh to execute correctly.

suganthanraj commented 6 days ago

Below is the inventory

[sql_nodes]
sqlnode1.example.com ansible_host='192.168.56.72'
sqlnode2.example.com ansible_host='192.168.56.73'
sqlnode3.example.com ansible_host='192.168.56.74'

[primary]
sqlnode1.example.com

[secondary]
sqlnode2.example.com

[tertiary]
sqlnode3.example.com

[all:vars]
ansible_connection=winrm
ansible_user=Administrator
ansible_password="Admin@123"
ansible_port=5985
ansible_winrm_transport=ntlm

Below is the main.yml playbook

---
- name: Manage and Configure SQL Server HA and DR
  hosts: sql_nodes
  gather_facts: false
  become_method: runas
  become: true
  become_user: administrator
  become_flags: logon_flags=
  vars_files:    
    - variables.yml
  tasks:
    - ansible.builtin.include_role:
        name: /root/.ansible/collections/ansible_collections/lowlydba/sqlserver/plugins/modules
    - name: Create Availability Group
      lowlydba.sqlserver.availability_group:
        sql_instance: SQLNODE1\INST1
        ag_name: AG_MyDatabase
        sql_username: domain\administrator
        sql_password: Admin@123
suganthanraj commented 6 days ago

Its also worth noting that if you are intending to execute this on the controller, you'll need to use a connection hack (https://github.com/lowlydba/lowlydba.sqlserver/blob/main/tests/integration/targets/setup_sqlserver_test_plugins/connection_plugins/local_pwsh.py) like we do in the testing pipelines in order to get pwsh to execute correctly.

How to use this in my playbook?

suganthanraj commented 6 days ago

Configuring Availability Group failed: The term 'Get-DbaAvailabilityGroup' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again

This indicates that dbatools is not actually available on the host you're running against. Try adding some basic pwsh debug tasks to ensure that you can execute dbatools functions on the host.

Please also include your playbook and inventory sample for a MVP.

I already installled the dbatools powershell module in the target windows machine.