Solved

Commvault Ansible


Badge +3

Anyone using CVPySDK and Ansible?  

I am unable to get it to function.  I have pip installed and can run the commcell functions from within the python interpreter.

When I attempt to use it in a playbook, I get an error…

 

ERROR! couldn’t resolve module/action ‘commvault’

 

Ansible 2.10.7

python 3.6.8.

 

Ken

icon

Best answer by Sachin 10 April 2021, 15:11

View original

18 replies

Userlevel 7
Badge +15

Hi @keng 

Thank you for the question and welcome to the Community!

Just to cover off some basics, please confirm the initial steps have been performed from:

https://github.com/Commvault/ansible

Installing CVPySDK

CVPySDK can be installed directly from PyPI using pip:

>>> pip install cvpysdk

CVPySDK is available on GitHub here

It can also be installed from source.

After downloading, from within the cvpysdk directory, execute:

>>> python setup.py install

 

Thanks,

Stuart

Badge +3

Hi @keng 

Thank you for the question and welcome to the Community!

Just to cover off some basics, please confirm the initial steps have been performed from:

https://github.com/Commvault/ansible

Installing CVPySDK

CVPySDK can be installed directly from PyPI using pip:

>>> pip install cvpysdk

CVPySDK is available on GitHub here

It can also be installed from source.

After downloading, from within the cvpysdk directory, execute:

>>> python setup.py install

 

Thanks,

Stuart

 

Thanks for the response Stuart!

 

As I indicated in my initial post, I have already installed using the PIP method and I am am able to run the scripts from the python prompt.  

I may be wrong but I thought that the “python setup.py install”  command was to be used only if downloading directly.   I cannot find “setup.py” in the cvpysdk directory after installing using PIP.

Ken

 

 

Badge +3

added info - I am running on Centos8 release 8.2.2004

Userlevel 7
Badge +15

Hi @keng 

I have just attempted following those steps myself on a default lab Commserve and I’m seeing the same as you - there is no setup.py in the cvpysdk directory.

I’ll follow this up internally to see what the process is here.

From the error message, it looks like the python commvault module isn’t fully registered, which I’m assuming should be performed by the setup script, but as we are both seeing this isn’t present in the directory.

I’ll get back to you once I have more info.

Thanks,

Stuart

Badge +3

Thank you!

Badge +2

Hi @keng,

 

Looks like the commvault ansible module is not detected by ansible. This module is a local module and is not automatically added to the ansible library. You might have to add this to the ANSIBLE_LIBRARY environment variable. For details refer to https://docs.ansible.com/ansible/latest/dev_guide/developing_locally.html

 

Or you can also clone the commvault ansible module and use it exactly the same way, having library directory in the current working directory. 
So if your file is cv_backup.yaml then your folder structure should be like

 

ansible_files/

                library/commvault.py

                cv_backup.yaml

 

Please let us know if you need any other help.

 

Thanks

 

Badge +3

Thanks Sachin,

 

I have attempted what I think you have recommended.

my playbook is:

ansiblevenv/cvlogin.yml

I have created ansiblevenv/library

Within the library folder I have copied all *py in cvpysdk

ie…

ansiblevenv\library\commcell.py

ansiblevenv\library\job.py

…. (etc)

I am still get the same error.

 

I have also used the command line argument -M to point to the original installation folder..

ansible-playbook -M /usr/local/lib/python3.6/site-packages/cvpysdk  “playbook.yml”

same error.

Ken

 

Badge +2

Hi @keng,

 

Looks like you have copied the cvpysdk files under the library directory. But we have to copy the commvault ansible module (commvault.py) file.

 

You can get a copy of the commvault module from the GitHub repository.

https://github.com/Commvault/ansible/tree/master/library

 

After copying the ansible module your directory structure should look something like below.

ansiblevenv\library\commvault.py

 

Thanks,

Sachin

Badge +3

Thank you Sachin!

 

That was the problem.  I was confused (as a new Ansible developer) as to what the module was.

I thought that cvpysdk was the module and missed that the git repository and cvpysdk were two different things.

 

I have now successfully authenticated with Ansible.

Thanks for your help.

 

Ken

Badge

Hi,

I am running into similar issue and I get following error. Can anyone please help?

 

ansible: 2.11.6

python: 3.9.9

 

As stated above, I did download ansible Commvault module from GitHub into library directory but still get following issue:


TASK [Login] *************************************************************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"msg": "module (commvault) is missing interpreter line"}

Userlevel 7
Badge +23

@Tej , I checked out database for that error and didn’t find anything.

I would suggest creating a case with support.

Please share the solution here once resolved 😎

Badge

Hi Mike,

I was able to solve it on my own. I had ended up creating Commvault’s python file and ansible.cfg in ansiblevenv\library folder and voila it worked like a charm!! 

Thank you very much.

Userlevel 7
Badge +23

Thanks for sharing, @Tej !

Badge

Hi Wondering if Commvault has any module in ansible to support Server restore rather than just files restore. Currently below is what I am using to restore a file in ansible.

 

- name: Restore

commvault:

operation: "restore_in_place"

entity_type: subclient

commcell: "{{ commcell }}"

entity: {

client: "vcentertest",

agent: "Virtual Server",

backupset: "defaultbackupset",

subclient: "BackupTesting"

}

args: {

paths: [\tst-cvlt-ansi\C$\Windows\Logs\CBS]

}

register: restore_job

Userlevel 7
Badge +23

@Tej , I’ll tag @Sachin in for his reply!

Badge +2

Hi @Tej,

 

Can you please help me understand what you mean by Server restore here? Are you trying full VM restore? If yes, which hypervisor is this?

 

Thanks,

Sachin

Badge

Hi Sachin,

 

Thank you for your reply.

 

Yes I am trying to perform a full VM-Backup and Restore on Esxi 7.0, VMware client. 

Badge

Hi @Tej 

Please use this script

- name: full backup
commvault:
operation: "backup"
entity_type: subclient
commcell: "{{ commcell }}"
entity: {
client: "{{ client }}",
agent: "Virtual Server",
backupset: "{{ backupset }}",
subclient: "{{ subclient }}"
}
args: {
backup_level: "Full"
}

- name: restore
commvault:
operation: "full_vm_restore_in_place"
entity_type: subclient
commcell: "{{ commcell }}"
entity: {
client: "{{ client }}",
agent: "Virtual Server",
backupset: "{{ backupset }}",
subclient: "{{ subclient }}"
}
args: {
vm_to_restore: "{{ vm_name }}"
}

 

You can check out other args you can pass to the restore function here: https://github.com/Commvault/cvpysdk/blob/fbcbb183d2c66c4156a2b9aa1e5a17b245866a3f/cvpysdk/subclients/virtualserver/vmware.py#L85

Reply