为 Ansible 安装 Azure 支持

Ron*_*rin 3 azure ansible python-packaging

我正在尝试让 Ansible 将资源部署到 Azure 云,但在让它开始工作时出现错误。我全新安装了 Ubuntu 14.04

我已经通过运行以下命令安装了 ansible:

 - sudo apt-get install software-properties-common
 - sudo apt-add-repository ppa:ansible/ansible
 - sudo apt-get update
 - sudo apt-get install ansible
Run Code Online (Sandbox Code Playgroud)

我还通过运行命令安装了 pip

 - sudo easy_install pip
Run Code Online (Sandbox Code Playgroud)

这一切都是为了在服务器上安装 ansible。然后我按照此处给出的说明开始使用 Ansible 的 Azure 组件。

我运行命令sudo pip install "azure==2.0.0rc5"以获取 Azure Python SDK。然后我创建了一个简单的 yaml 文件来创建资源组,当我通过运行命令运行剧本时,ansible-playbook test.yml -vvv返回了以下错误:

致命:[本地主机]:失败!=> {“更改”:false,“失败”:true,“调用”:{“module_args”:{“ad_user”:null,“append_tags”:true,“client_id”:null,“force”:false,“ location”:null,“name”:“test”,“password”:null,“profile”:null,“secret”:null,“state”:“present”,“subscription_id”:null,“tags”:null , "tenant": null}, "module_name": "azure_rm_resourcegroup"}, "msg": "你安装了 azure==2.0.0rc5 吗?试试pip install azure==2.0.0rc5- 没有名为 enum 的模块"}

Ric*_*Vel 5

Ansible 3.0+ / ansible-core 2.10+ 的新答案:

要安装 Azure 支持,请使用Ansible Azure 集合,如下所示:

# Install dependencies
curl -O https://raw.githubusercontent.com/ansible-collections/azure/dev/requirements-azure.txt
pip install -r requirements-azure.txt

# Install collection
ansible-galaxy collection install azure.azcollection
Run Code Online (Sandbox Code Playgroud)
  • requirements-azure.txt指定了所有库的版本,所以如果升级集合版本最好重新安装这些
  • 考虑将其签入“固定”版本的依赖项
  • 您可能还想固定收藏版本

作为Ansible 集合,此 Ansible Azure 支持现在可以在 Ansible 核心发布过程之外更快地更新。

为ansible -core 2.10+更新,包含在 Ansible 3.0 及更高版本中。


原始答案适用于 Ansible 2.9:

为 Ansible 安装 Azure 包的最简单、最可靠的方法是:

pip install ansible[azure]==2.8.6
Run Code Online (Sandbox Code Playgroud)

这将安装此 Ansible 版本所需的 Azure 依赖项。如果要使用最新版本,请省略该==2.8.6部分。

这是有效的,因为 Ansible 项目定义了Azure 支持所需的确切依赖项版本(截至 2.9.9)作为其 Python 打包设置中的“额外”。