gheesh / ansible-ovh-dns

Ansible module for accessing the OVH DNS API
GNU General Public License v3.0
45 stars 20 forks source link

python-ovh #21

Open sisihagen opened 2 years ago

sisihagen commented 2 years ago

Thanks for the module is what I search. But it will not work. There is no ovh module installed but it is.

(.py_ansible) 18:31:07[siefke]{ansible} $  ansible-playbook playbooks/service/ovh_dns.yml -vv
ansible-playbook [core 2.12.6]
  config file = /home/siefke/Öffentlich/projects/coding/ansible/ansible.cfg
  configured module search path = ['/home/siefke/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/siefke/.py_ansible/lib/python3.10/site-packages/ansible
  ansible collection location = /home/siefke/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/siefke/.py_ansible/bin/ansible-playbook
  python version = 3.10.4 (main, May 14 2022, 05:21:19) [GCC 12.1.0]
  jinja version = 3.1.2
  libyaml = True
Using /home/siefke/Öffentlich/projects/coding/ansible/ansible.cfg as config file
redirecting (type: callback) ansible.builtin.yaml to community.general.yaml
redirecting (type: callback) ansible.builtin.yaml to community.general.yaml
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: ovh_dns.yml ************************************************************************************************************************************************************************************************************************
1 plays in playbooks/service/ovh_dns.yml

PLAY [localhost] *****************************************************************************************************************************************************************************************************************************
META: ran handlers

TASK [Create a A record for subdomain] *******************************************************************************************************************************************************************************************************
task path: /home/siefke/Öffentlich/projects/coding/ansible/playbooks/service/ovh_dns.yml:7
fatal: [localhost]: FAILED! => changed=false 
  msg: ovh python module is required to run this module.
    to retry, use: --limit @/home/siefke/.ansible/retry-files/ovh_dns.retry

PLAY RECAP ***********************************************************************************************************************************************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0 
(.py_ansible) 18:31:17[siefke]{ansible} $  pip show ovh
Name: ovh
Version: 1.0.0
Summary: "Official module to perform HTTP requests to the OVHcloud APIs"
Home-page: https://api.ovh.com
Author: OVHcloud team - Romain Beuque
Author-email: api@ml.ovh.net
License: BSD
Location: /home/siefke/.py_ansible/lib/python3.10/site-packages
Requires: requests
Required-by: 

Need the module a specific version of Ansible / python-ovh?

lalmeras commented 2 years ago

Your ansible/python-ovh versions should be fine.

Can you add a verbosity level (-vvv) to print information on python interpreter ?

Can you check in an interactive python shell that import ovh is working fine ?

lalmeras commented 2 years ago

(Check your log for any secret information before posting - any OVH_* environment settings)

sisihagen commented 2 years ago

thanks for help.

(.py_ansible) 14:54:34[siefke]{ansible} $  python 
Python 3.10.4 (main, May 14 2022, 05:21:19) [GCC 12.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ovh
>>> from ovh.exceptions import APIError
>>> 

The verbose out I attach as file.

ovhdns.txt

lalmeras commented 2 years ago

I think your ansible connection setting is responsible for your issue.

There are two side for an ansible play: controller and managed side. python-ovh is expected on the managed side.

Working setting : python-ovh is installed on the controller side, task is delegated to localhost and localhost transport is set to local. So managed-side ansible use same python runtime as the controller.

Your setting (as I understand it) : your task is played on localhost, but your transport is mitogen (I don't kown this layer). And it seems that your ansible_python_interpreter is the system python installation, not your ansible-dedicated python environment.

You should either try:

sisihagen commented 2 years ago

Thanks yes I had use virtualenv for ansible. Now change all to host and it work. Okay key problem I not know why cause I use same ApplicationKey etc. for using letsencrypt. But I worked now.

ansible-playbook playbooks/service/ovh_dns.yml -e ansible_connection=local -vv
ansible-playbook [core 2.13.0]
  config file = /home/siefke/Öffentlich/projects/coding/ansible/ansible.cfg
  configured module search path = ['/home/siefke/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.10/site-packages/ansible
  ansible collection location = /home/siefke/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible-playbook
  python version = 3.10.4 (main, May 14 2022, 05:21:19) [GCC 12.1.0]
  jinja version = 3.1.2
  libyaml = True
Using /home/siefke/Öffentlich/projects/coding/ansible/ansible.cfg as config file
redirecting (type: callback) ansible.builtin.yaml to community.general.yaml
redirecting (type: callback) ansible.builtin.yaml to community.general.yaml
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: ovh_dns.yml ************************************************************************************************************************************************************************************************************************
1 plays in playbooks/service/ovh_dns.yml

PLAY [localhost] *****************************************************************************************************************************************************************************************************************************
META: ran handlers

TASK [Create a A record for subdomain] *******************************************************************************************************************************************************************************************************
task path: /home/siefke/Öffentlich/projects/coding/ansible/playbooks/service/ovh_dns.yml:7
fatal: [localhost]: FAILED! => changed=false 
  msg: |-
    Unable to call OVH api for getting the list of domains. Check application key, secret, consumer key & parameters. Error returned by OVH api is: "This call has not been granted
    OVH-Query-ID: EU.ext-3.629a5728.30066.0fc47719-d12f-4380-9dea-2352146c0924".
    to retry, use: --limit @/home/siefke/.ansible/retry-files/ovh_dns.retry

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

With localhost yes, I set it in playbook. Not need this in it?

- hosts: localhost
  become: True

  tasks:
    - name: "Create a A record for subdomain"
      ovh_dns:
        state: present
        domain: sisi-systems.ovh
        subdomain: australia
        type: AAAA
        target: 2402:1f00:8100:400::17f6
        ttl: 3600
        endpoint: ovh-eu
        application_key: ''
        application_secret: ''
        consumer_key: ''
      tags: ovh_subdomain

Thanks for help and find the mistake. Sorry I had stolen your time.

lalmeras commented 2 years ago

If you want to test your credentials, OVH api tools generate python-ovh scripts. It seems you ansible playbook triggers a forbidden exception when you call this service : https://api.ovh.com/console/#/domain/zone/%7BzoneName%7D/record~GET (see Python tab).

Not sure what your second question is about. Can you elaborate ?

Not sure about the example you provide, with credentials passed as task variables; credentials are meant to be provided with environment (see README) and the current code-base should trigger a Unsupported parameters for (ovh_dns) module: application_key. error with your playbook example. Do you use a modified ansible-ovh-dns version ?