vsphere_guestはAnsible 1.6からあるモジュールである。VMware vSphere を通じてvCenterなしでも直接操作できる。vCenterを介しても可能。ただその場合はAnsible v2.2 から利用可能なvmware_guestを使う方がよい。
記事投稿時点ではPreview
既存のVMをブートアップ
既存で構成されているVMをブートアップさせるときは以下のように書く。
hosts
localhost ansible_connection=local
site.yml
- hosts: localhost
connection: local
become: true
become_user: root
gather_facts: no
tasks
- name: Boot up instance
vsphere_guest:
vcenter_hostname: 192.168.0.12
username: root
password: password
guest: testvm
state: powered_on
validate_certs: False
esxi:
datacenter: ha-datacenter
hostname: 192.168.0.12
パラメータ自体に一部、vcenterほにゃららとあるので紛らわしいが、そこにはESXiのアドレスやユーザ名、パスワードを入れる。そして、datacenterにはha-datacenterと入れる。これによりスタンドアロンで実行できる。つまり、ESXi直操作。
「validate_certs: False」 は
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "pysphere does not support verifying certificates with python < 2.7.9. Either update python or set validate_certs=False on the task"}
と怒られたので入れた。
実行
$ ansible-playbook -i hosts site.yml
PLAY [localhost] ***************************************************************
TASK [Boot up instance] ********************************************************
changed: [localhost]
PLAY RECAP *********************************************************************
localhost : ok=1 changed=1 unreachable=0 failed=0
冪等性もok
$ ansible-playbook -i hosts site.yml
PLAY [localhost] ***************************************************************
TASK [Boot up instance] ********************************************************
ok: [localhost]
PLAY RECAP *********************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0
テスト環境
- vSphere ESXi 5.5
- Ubuntu 14.04.2 LTS
- Ansible 2.2.1
- Python 2.7.6
- pysphere 0.1.7