如何在Raspbian上安装Ansible?

4

我想在我的树莓派(raspbian/jessie)上安装Ansible,以便我可以维护它。不幸的是,我似乎无法安装它。到目前为止,我已经尝试了APT和PIP,但每个都有障碍。

APT

pi@retropie:~ $ sudo apt-add-repository ppa:ansible/ansible

Traceback (most recent call last):
  File "/usr/bin/apt-add-repository", line 167, in <module>
    sp = SoftwareProperties(options=options)
  File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 105, in __init__
    self.reload_sourceslist()
  File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 595, in reload_sourceslist
    self.distro.get_sources(self.sourceslist)
  File "/usr/lib/python3/dist-packages/aptsources/distro.py", line 89, in get_sources
    (self.id, self.codename))
aptsources.distro.NoDistroTemplateException: Error: could not find a distribution template for Raspbian/jessie

PIP (Python 2.7.9, pip 1.5.6)

pi@retropie:~ $ sudo pip install ansible

Downloading/unpacking ansible
  Downloading ansible-2.4.1.0.tar.gz (6.7MB): 6.7MB downloaded

    no previously-included directories found matching 'ticket_stubs'
    no previously-included directories found matching 'hacking'
Downloading/unpacking jinja2 (from ansible)
  Downloading Jinja2-2.9.6-py2.py3-none-any.whl (340kB): 340kB downloaded
Downloading/unpacking PyYAML (from ansible)
  Downloading PyYAML-3.12.tar.gz (253kB): 253kB downloaded
  Running setup.py (path:/tmp/pip-build-bsUTB2/PyYAML/setup.py) egg_info for package PyYAML

Downloading/unpacking paramiko (from ansible)
  Downloading paramiko-2.3.1-py2.py3-none-any.whl (182kB): 182kB downloaded
Downloading/unpacking cryptography (from ansible)
  Downloading cryptography-2.1.2.tar.gz (441kB): 441kB downloaded
  Running setup.py (path:/tmp/pip-build-bsUTB2/cryptography/setup.py) egg_info for package cryptography
    error in cryptography setup command: Invalid environment marker: python_version < '3'
    Complete output from command python setup.py egg_info:
    error in cryptography setup command: Invalid environment marker: python_version < '3'

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip-build-bsUTB2/cryptography
Storing debug log for failure in /root/.pip/pip.log

Python 3

从上述错误可以看出,"cryptography" 表示它需要 > python3。我查看了 安装要求,发现如果使用3,则需要python 3.5+。Rasbian 自带 3.4 ...

然后我尝试使用一些 ppa(ppa:jonathonf/python-3.6 和 ppa:deadsnakes/ppa)来安装 Python 3.6,但是在 raspbian/jessie 中也没有可用的发行版。

之后,我开始考虑从源代码中获取并编译 Python,但我预计会遇到另一个障碍。

唉...

总之,有人有什么想法可以让我在 Raspberry Pi 上安装 Ansible 吗?


1
Cryptography 2.1.2 根据软件包列表和它们的 Github,确实支持 Python 2.7。你在这里遇到了其他问题。 - Matt Schuchard
2个回答

6
略微有点老的问题,但当你在谷歌搜索如何在Raspbian上安装Ansible时,它是第一个结果,所以我想更新一下它。 如果你正在运行stretch(或stretch-lite)
你可以只需执行:
sudo apt-get install ansible

然而,目前Raspbian存储库中的Ansbile版本为2.2,有些过时。按照Ansible安装页面的说明(稍作修改以克服一些错误),您可以执行以下操作:首先运行
sudo apt-get install dirmngr

编辑你的/etc/apt/sources.list文件并追加以下内容。
deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main

然后运行

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367    
sudo apt-get update 
sudo apt-get install ansible

今天你将获得版本2.7.8。编辑以包含缺少的命令(感谢 SpacePope)和正确的格式。

对于 Hamza M 的建议,只需要做一个小小的补充:您需要运行以下命令来获取该源的公钥 -sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367 - SpacePope
1
非常感谢这个答案。我一直在努力通过源代码或Python安装最新版本的Ansible,所以这是一个很好的发现。完美地解决了我的问题。干杯! - droid-zilla

2

Jessie于2015年发布,现已正式过时。Stretch是当前的Raspbian软件仓库,它带有python3.5且不需要添加PPAs。

您可以使用pip3轻松安装Ansible。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接