Skip to main content
  1. Posts/

Fixing install ansible-pylibssh on macOS (Apple Silicon)

·195 words·1 min·
kb macos ansible fix
Maximilian Thoma
Author
Maximilian Thoma
network engineer
Table of Contents

On macOS (Apple Silicon), I had trouble installing ansible-pylibssh because it could not find all the required sources.

Error
#

# pip install ansible-pylibssh
Collecting ansible-pylibssh
  Using cached ansible-pylibssh-1.2.0.post4.tar.gz (133 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: ansible-pylibssh
  Building wheel for ansible-pylibssh (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Building wheel for ansible-pylibssh (pyproject.toml) did not run successfully.
exit code: 1
  ╰─> [6 lines of output]
      [1/1] Cythonizing /private/var/folders/s1/0057qklj5rs4bd2vysfdr6lh0000gn/T/.tmp-ansible-pylibssh-pep517-rzhivdqm/src/src/pylibsshext/_libssh_version.pyx
      /private/var/folders/s1/0057qklj5rs4bd2vysfdr6lh0000gn/T/.tmp-ansible-pylibssh-pep517-rzhivdqm/src/src/pylibsshext/_libssh_version.c:1236:10: fatal error: 'libssh/libssh.h' file not found
      #include "libssh/libssh.h"
               ^~~~~~~~~~~~~~~~~
      1 error generated.
      error: command '/usr/bin/clang' failed with exit code 1
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for ansible-pylibssh
Failed to build ansible-pylibssh
ERROR: Could not build wheels for ansible-pylibssh, which is required to install pyproject.toml-based projects

Fix
#

Install libssh with homebrew.

brew install libssh

Run in your python venv pip install ansible-libssh with the following compiler flags.

CFLAGS="-I $(brew --prefix)/include -I ext -L $(brew --prefix)/lib -lssh" pip install ansible-pylibssh

Source: stackoverflow - Cannot install ansible-pylibssh on macOS

Related

Netdevops python libraries toolbox
·1720 words·9 mins
netdevops blog python apiflask flask loguru ciscoconfparse dynaconf pymongo rq netmiko paramiko ansible pandas ntc_templates textfsm requests
In the ever-evolving landscape of network management and automation, the role of Network DevOps has become increasingly pivotal.
Use Ansible Tower API
·349 words·2 mins
netdevops blog python ansible tower api
Here are some code examples to use the Ansible Tower API from python scripts.
Interaction with REST API <-> Ansible playbook
·473 words·3 mins
netdevops blog ansible api
This is a short example how you interact from an ansible playbook with a rest api.