Skip to content

Instantly share code, notes, and snippets.

@h-hirokawa
Last active October 27, 2015 07:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h-hirokawa/7dd15ad30055e787ef03 to your computer and use it in GitHub Desktop.
Save h-hirokawa/7dd15ad30055e787ef03 to your computer and use it in GitHub Desktop.
---
- name: SSH鍵をアップロード
cs_sshkeypair:
name: sample-ssh-key
public_key: "{{ lookup('file', public_key_path) }}"
register: sshkeypair
- name: VMインスタンス作成
cs_instance:
name: centosvm
hypervisor: VMware
template: CentOS 7.1 64-bit
service_offering: light.S1
ssh_key: sample-ssh-key
register: vm_status
- block:
- name: グローバルIP追加
cs_ip_address:
register: global_ip
- name: スタティックNAT適用
cs_staticnat:
ip_address: "{{ global_ip.ip_address }}"
vm: "{{ vm_status.name }}"
when: not vm_status.get('public_ip')
- set_fact:
vm_public_ip: "{{ vm_status.get('public_ip',
global_ip.ip_address) }}"
- name: 22,80番ポート開放
cs_firewall:
ip_address: "{{ vm_public_ip }}"
port: "{{ item }}"
protocol: tcp
with_items:
- 22
- 80
- name: VM起動完了まで待機
wait_for:
host: "{{ vm_public_ip }}"
port: 22
- name: VMインスタンスをansibleのhostに追加
add_host:
name: idcf-{{ vm_status.name }}
groups: ansible-target
ansible_ssh_host: "{{ vm_public_ip }}"
ansible_ssh_private_key_file: "{{ private_key_path }}"
ansible_ssh_user: root
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment