如何在ansible中配置azure模块
how to configure azure module in ansible
如主题所述,我想在 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 中指定)
为 VM 生成 ssh 密钥
openssl req -x509 -key ~/.ssh/id_rsa -nodes -days 365 -newkey rsa:2048 -out ~/.ssh/ssh_key.pem
- 为生成的密钥授予所有者权限
chmod 600 ~/.ssh/ssh_key.pem
将此证书上传到您的 Azure 订阅。我是通过 node azure-cli
做到的
yum install npm or apt-get install npm
nsudo npm install -g azure-cli
azure account download
正在通过显示 link 下载您的订阅文件。
azure account import <path to downloaded file>
为您的订阅导出管理证书
azure account cert export -f ~/.ssh/manage.cer
我还需要通过 azurecli 获取 VM 映像名称,因为我在 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"
此剧本将创建具有 admin
用户和 password
的 Centos6 机器。目前我无法使用 ssh-key 身份验证创建机器。我不断收到 msg: password parameter is required for new instance
更新:修复了证书生成过程。
如主题所述,我想在 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 中指定)
为 VM 生成 ssh 密钥
openssl req -x509 -key ~/.ssh/id_rsa -nodes -days 365 -newkey rsa:2048 -out ~/.ssh/ssh_key.pem
- 为生成的密钥授予所有者权限
chmod 600 ~/.ssh/ssh_key.pem
将此证书上传到您的 Azure 订阅。我是通过 node azure-cli
做到的yum install npm or apt-get install npm
nsudo npm install -g azure-cli
azure account download
正在通过显示 link 下载您的订阅文件。
azure account import <path to downloaded file>
为您的订阅导出管理证书
azure account cert export -f ~/.ssh/manage.cer
我还需要通过 azurecli 获取 VM 映像名称,因为我在 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"
此剧本将创建具有 admin
用户和 password
的 Centos6 机器。目前我无法使用 ssh-key 身份验证创建机器。我不断收到 msg: password parameter is required for new instance
更新:修复了证书生成过程。