Code Monkey home page Code Monkey logo

Comments (11)

resmo avatar resmo commented on May 26, 2024 4

not a bug

I assume you installed ansible with python2 pip. But hcloud is python3 only. You should consider to use python3 venv anyway to be independend of systems python and OS.

apt-get install python3 python3-pip python3-venv
cd to-your-playbooks
python3 -m venv venv
source venv/bin/activate

# you are now in a venv, install python deps
pip install ansible hcloud-python

# to get your PATH updated, leave venv with deactivate and activate again
deactivate
source venv/bin/activate

ansible --version

from hcloud-python.

psi-4ward avatar psi-4ward commented on May 26, 2024 3

Same here on arch-linux

Ansible reports Python /usr/bin/python

$ /usr/bin/python --version
Python 3.9.7

$ pip --version
pip 20.3.4 from /usr/lib/python3.9/site-packages/pip (python 3.9)

$ pip install hcloud-python
Defaulting to user installation because normal site-packages is not writeable
ERROR: Could not find a version that satisfies the requirement hcloud-python
ERROR: No matching distribution found for hcloud-python

$ pip install hcloud
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: hcloud in /home/user/.local/lib/python3.9/site-packages (1.16.0)

SOLVED:
The playbook uses become (root) and the hcloud-pkg was installed for the user.
So become: false in the task solves it. :)

from hcloud-python.

resmo avatar resmo commented on May 26, 2024 2

hi @jobetinfosec

Debian packages for ansible used to rely on python2 and that is why it will not use python3 libraries. Install ansible in a venv for python3 as I posted.

from hcloud-python.

jimkoen avatar jimkoen commented on May 26, 2024 1

Having the same issue here, on Mac OS Monterey with Python/Pip 3.10

EDIT: For anyone encountering this error, while the error message calls the package hcloud-python, when installing it via pip, you do in fact want just want hcloud

pip install hcloud

from hcloud-python.

jobetinfosec avatar jobetinfosec commented on May 26, 2024

Hi resmo,
I didn't install Ansible with pip 2, but directly with Ubuntu's apt manager. I installed hcloud with pip3 (pip3 install hcloud).
I tried once again with 2 differents Ubuntu versions, 20.04 (with Python 3.8) and 21.10 (Python 3.9) but both are throwing the same error: Failed to import the required Python library (hcloud-python) on computer's Python /usr/bin/python3

The only laptop where this is working is on a MacBook Pro (Python 3.9 and hcloud 1.12).
Comparing a bit both installations (Mac and Ubuntu) I noticed something that maybe could be relevant...
running the command which hcloud shows /usr/local/bin/hcloud (in Mac laptop) but nothing shows up in the Ubuntu laptop....

from hcloud-python.

jobetinfosec avatar jobetinfosec commented on May 26, 2024

Bonjour @resmo

Now the problem with hcloud is gone, but now a SSH key not found error shows up... ;-)
In my Ansible's hosts file I have this directive: ansible_ssh_private_key_file=~/.ssh/id_rsa

When running Ansible in a virtual environment, does it lookup for files outside the virtual env? or is limited only to it?

from hcloud-python.

resmo avatar resmo commented on May 26, 2024

@jobetinfosec lookup is not limited to the venv, the venv is only for python dependency it is not a "container" or a "secured environment"

Nevertheless, I tested it and confirm this worked.

- hosts: localhost
  tasks:
  - debug:
      msg: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}"

from hcloud-python.

olegsidokhmetov avatar olegsidokhmetov commented on May 26, 2024

I have the same issue ansible-playbook -vvv server-create-init.yml

my playbook

---

- hosts: localhost 
  gather_facts: false
  become: false 
  vars_files:
    - /etc/ansible/roles/server-create/defaults/main.yml
    - /etc/ansible/roles/server-create/vars/main.yml

  roles:
    - role: "/etc/ansible/roles/server-create"

Task:

---

- name: Create a basic server
  hcloud_server:
    api_token: "{{ token }}"
    name: "{{ item.name }}"
    server_type: "{{ item.server_type }}"
    image: "{{ item.os_image }}"
    state: present
  register: server
  with_items: "{{ server }}"

Can not find any solves of this issue (hcloud-python) . Could you please help with solution?

root@ip-172-31-27-151:/usr/bin# pip install ansible hcloud-python

Requirement already satisfied: ansible in /usr/lib/python3/dist-packages (5.4.0)
ERROR: Could not find a version that satisfies the requirement hcloud-python (from versions: none)
ERROR: No matching distribution found for hcloud-python

root@ip-172-31-27-151:/usr/bin# python3 --version

Python 3.8.10

/etc/ansible/hosts

[Server_hetzner]
localhost ansible_connection=local

[all:vars]
ansible_python_interpreter=/usr/bin/python3

root@ip-172-31-27-151:/usr/bin# cat /etc/os-release

NAME="Ubuntu"
VERSION="20.04.4 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.4 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

from hcloud-python.

RogelioCodes avatar RogelioCodes commented on May 26, 2024

I have the same issue ansible-playbook -vvv server-create-init.yml

my playbook

---

- hosts: localhost 
  gather_facts: false
  become: false 
  vars_files:
    - /etc/ansible/roles/server-create/defaults/main.yml
    - /etc/ansible/roles/server-create/vars/main.yml

  roles:
    - role: "/etc/ansible/roles/server-create"

Task:

---

- name: Create a basic server
  hcloud_server:
    api_token: "{{ token }}"
    name: "{{ item.name }}"
    server_type: "{{ item.server_type }}"
    image: "{{ item.os_image }}"
    state: present
  register: server
  with_items: "{{ server }}"

Can not find any solves of this issue (hcloud-python) . Could you please help with solution?

root@ip-172-31-27-151:/usr/bin# pip install ansible hcloud-python

Requirement already satisfied: ansible in /usr/lib/python3/dist-packages (5.4.0)
ERROR: Could not find a version that satisfies the requirement hcloud-python (from versions: none)
ERROR: No matching distribution found for hcloud-python

root@ip-172-31-27-151:/usr/bin# python3 --version

Python 3.8.10

/etc/ansible/hosts

[Server_hetzner]
localhost ansible_connection=local

[all:vars]
ansible_python_interpreter=/usr/bin/python3

root@ip-172-31-27-151:/usr/bin# cat /etc/os-release

NAME="Ubuntu"
VERSION="20.04.4 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.4 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

I just wanted to check in and say the same thing started happening to me about 4 days ago as well. I was out of office for the weekend and only noticed today(monday)

from hcloud-python.

github-actions avatar github-actions commented on May 26, 2024

This issue has been marked as stale because it has not had recent activity. The bot will close the issue if no further action occurs.

from hcloud-python.

cx-networks-gmbh avatar cx-networks-gmbh commented on May 26, 2024

Maybe this can help someone in the future:
We had the same issue on ubuntu 22.04. We were moving from an installation without virtual env to an installation with virtual env. The tasks originally executed on an "ansible" group:

# hosts.yml
---
all:
  hosts:
    ansible:
      ansible_host: localhost
      ansible_connection: local
# TestPlaybook.yml
---
- name: Get some infos
  hosts: ansible
  gather_facts: false
  tasks:
    - name: Gather facts about the cloud # <-- Fails
      hetzner.hcloud.hcloud_server_info:
        name: "testhost"
        api_token: "{{ hetzner_cloud_api_token }}"

Therefore ansible set the python3 interpreter to usr/bin/python3 but the python interpreter was in the virtual enviroment ~/venv/bin/python3. Setting the hosts to just localhost fixed it for us.

# TestPlaybook.yml
---
- name: Get some infos
  hosts: localhost
  gather_facts: false
  tasks:
    - name: Gather facts about the cloud # <-- Fails
      hetzner.hcloud.hcloud_server_info:
        name: "testhost"
        api_token: "{{ hetzner_cloud_api_token }}"

Were are wondering about why the python interpreter in the venv does import the library without errors because it is just a symbolic link to /usr/bin/python3 but we did not investigate it further.

from hcloud-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.