如何在ansible中配置azure模块 [英] how to configure azure module in ansible

查看:23
本文介绍了如何在ansible中配置azure模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如题所述,我想在ansible中配置azure模块,也在github中找到azure模块但我不知道如何设置,请帮助我安装和配置.

As mention on subject,I want to configure azure module in ansible, also find out azure module in github but i don't not how to setup, please help me to install and configure.

推荐答案

  • 您需要安装 sudo pip install azure==0.11.1(最新的 azure 版本 > 1.0 与 ansible 不兼容,但这里是 github 问题 https://github.com/ansible/ansible-modules-core/pull/2114)

    • you need to install sudo pip install azure==0.11.1(newest azure version > 1.0 not compatible with ansible yet here is github issue https://github.com/ansible/ansible-modules-core/pull/2114)

      现在您需要在 azure 控制台中创建 Storage_account(稍后在 playbook 中指定)

      Now you need to create Storage_account in the azure console(and later specify it in the playbook)

      为虚拟机生成 ssh 密钥

      Generate ssh key for VM

      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 完成的

      • Upload this certificate to your azure subscription. I did it via node azure-cli

      yum install npm 或 apt-get install npm

      nsudo npm install -g azure-cli

      azure 帐号下载

      通过显示的链接下载您的订阅文件.

      downloading your subscription file by displayed link.

      azure 帐号导入<下载文件的路径>

      为您的订阅导出管理证书

      Export manage certificate for your subscription

      azure account cert export -f ~/.ssh/manage.cer

      我还需要通过 azurecli 获取 VM 映像名称,因为我在 azure 控制台中找不到它.

      Also I needed to get VM image name via azurecli because I could not find it in the azure console.

      azure vm 镜像列表 |grep CentOS

      然后您需要编写将启动 azure VM 的剧本:

      then you need to write playbook which will launch 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"
      

      这个 playbook 将使用 admin 用户和 password 创建 Centos6 机器.目前我无法使用 ssh-key 身份验证创建机器.我不断收到 msg:新实例需要密码参数

      This playbook will create Centos6 machine with admin user and password. Currently I could not create machine with ssh-key authentication. I'm keep getting msg: password parameter is required for new instance

      更新:固定证书生成程序.

      UPDATED: Fixed certificate generation procedure.

      这篇关于如何在ansible中配置azure模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆