正如主题中提到的,我想在ansible中配置azure模块,也在github中找到azure模块,但我不知道如何设置,请帮我安装和配置。
最佳答案
您需要安装
sudo pip install azure==0.11.1
(最新的 azure 版本 > 1.0 与 ansible 不兼容,但这里是 github 问题 https://github.com/ansible/ansible-modules-core/pull/2114 )现在您需要在 azure 控制台中创建 Storage_account(稍后在 playbook 中指定它)
为虚拟机生成 ssh key
openssl req -x509 -key ~/.ssh/id_rsa -nodes -days 365 -newkey rsa:2048 -out ~/.ssh/ssh_key.pem
- 仅授予所有者对生成的 key 的权限
chmod 600 ~/.ssh/ssh_key.pem
将此证书上传到您的 Azure 订阅。我是通过节点 azure-cli 完成的
yum install npm or apt-get install npm
nsudo npm install -g azure-cli
azure account download
通过显示的链接下载您的订阅文件。
azure account import <path to downloaded file>
导出您的订阅的管理证书
azure account cert export -f ~/.ssh/manage.cer
此外,我需要通过 azurecli 获取虚拟机镜像名称,因为我在 azure 控制台中找不到它。
azure vm image list | grep CentOS
然后您需要编写将启动azure VM的剧本:
- local_action:
module: azure
name: 'vm_name'
role_size: Small
image: '5112500ae3b842c8b9c604889f8753c3__OpenLogic-CentOS-67-20150815'
password: 'some_pass'
location: 'East US 2'
user: admin
wait: yes
subscription_id: 'some subscription'
management_cert_path: '~/.ssh/manage.cer'
storage_account: 'some account'
endpoints: '22,8080,80'
register: azure_vm
- add_host:
name: '{{ azure_vm.public_dns_name }}'
- name: wait when instance become ready to use
wait_for:
host: '{{ azure_vm.public_dns_name }}'
port: "22"
delay: "60"
timeout: "320"
state: "started"
此剧本将创建 Centos6 机器 admin
用户和 password
。目前我无法使用 ssh-key 身份验证创建机器。我不断收到msg: password parameter is required for new instance
更新:修复了证书生成过程。
关于azure - 如何在ansible中配置azure模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32907501/