Skip to content

Instantly share code, notes, and snippets.

@soundTricker
Created August 25, 2014 02:50
Show Gist options
  • Save soundTricker/3346745b1e3e3be3a515 to your computer and use it in GitHub Desktop.
Save soundTricker/3346745b1e3e3be3a515 to your computer and use it in GitHub Desktop.
GCE with Ansible
```
.
├── credentials/
│   ├── cacert.pem
│   ├── pkey.pem
│   ├── secrets.py*
│   └── secrets.pyc
├── inventory/
│   ├── gce.ini
│   ├── gce.py*
│   └── hosts
├── master.yaml
├── play.sh*
├── roles/
│   ├── network/
│   │   └── tasks/
│   └── servers/
│   └── tasks/
└── vars/
├── gce_auth.yml
└── instance.yml
```
[gce]
libcloud_secrets = {secrets.pyのパスを指定}
# If you are not going to use a 'secrets.py' file, you can set the necessary
# authorization parameters here.
gce_service_account_email_address = {直接指定}
gce_service_account_pem_file_path = {直接指定}
gce_project_id = {直接指定}
service_account_email: [email protected]
pem_file: /path/to/pkey.pem
project_id: project_id
[localhost]
127.0.0.1
region: asia-east1
instances:
- tags: webserver
names: www1,www2
type: f1-micro
image: centos-6
zone: asia-east1-a
members: ["asia-east1-a/www1", "asia-east1-a/www2"]
- name: Create new GCE instances
hosts: localhost
gather_facts: no
vars_files:
- "vars/instance.yml"
- "vars/gce_auth.yml"
tasks:
- name: Launch instances
local_action:
module: gce
instance_names: "{{ item.names }}"
machine_type: "{{ item.type }}"
image: "{{ item.image }}"
zone: "{{ item.zone }}"
tags: "{{item.tags}}"
service_account_email: "{{ service_account_email }}"
pem_file: "{{ pem_file }}"
project_id: "{{ project_id }}"
register: gce
with_items: instances
- name: Wait for SSH to be available
local_action: wait_for host={{ item.1.public_ip }} port=22
delay=20 timeout=30 state=started
with_subelements:
- gce.results
- instance_data
when: item.0.changed
- name: Install apache
hosts: tag_webserver
sudo: yes
tasks:
- name: install python-selinux
yum: pkg=libselinux-python state=latest
- name: disable selinux
selinux: state=disabled
- name: Update yum
yum: name=* state=latest
- name: Install apache
yum: name=httpd state=present
- name: start apache
service: name=httpd state=started
GCE_PARAMS=('[email protected]', '3.1で作成したpemファイルのfull path')
GCE_KEYWORD_PARAMS={'project':'project id'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment