通过 ansible 创建 openstack 虚拟机并部署应用(配置篇),ansibleopenstack


本文中的例子在 ansible 和 Ansible Tower 里都通过。

controller 对 openstack 的接入

本文里的 controller 是我的笔记本电脑,需要做以下配置:

建立 /etc/ansible/openstack.yml,内容如下

clouds:
  poc:
    auth:
      username: 'admin'
      password: xxxxxxxxxxxxxxxxxxxxx
      project_name: 'Haibin_Lee'
      auth_url: 'http://192.168.205.2:5000/v2.0'
    region_name: RegionOne
ansible:
  use_hostnames: True
  expand_hostvars: True
  fail_on_errors: True

auth 里的是 openstack 的相关验证信息。然后在你的 ansible 项目根目录下下载 openstack.py

wget https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/openstack.py
chmod +x openstack.py

验证你的配置

./openstack.py --list

如果正确,会列出你的 openstack 服务里的 hosts

然后在你的 ansible 项目根目录下放置独立的 ansible.cfg 文件并修改它的内容,

[defaults]
inventory      = ./openstack.py

这样就可以动态加载 openstack 里的服务器 inventory 了。

官方文档 http://docs.ansible.com/ansible/latest/intro_dynamic_inventory.html#example-openstack-external-inventory-script

手动在对应的 openstack 集群里创建一台虚拟机,用于执行 ansible 剧本,创建新虚拟机用。本文中命名为 openstack-connector,使用 ubuntu 14.04 版本系统。

在 openstack-connector 里安装以下软件

sudo apt-get install gcc libssl-dev sendmail python-pip
sudo -H pip install -U pip
sudo -H pip install cryptography shade

检查状态 ./openstack.py --host openstack-connector,你可以看到很长一串的 json 格式输出。

最后把你的公钥拷贝到 openstack-connector 里,我这台机器的 IP 是 192.168.220.57。

ssh-copy-id root@192.168.220.57

基本环境就搭好了。

接着请看 通过 ansible 创建 openstack 虚拟机并部署应用(实战篇)

相关内容