Skip to content

Commit

Permalink
Merge pull request #1 from Mahito/refact_playbooks
Browse files Browse the repository at this point in the history
[refactor] openstack playbook refactoring
  • Loading branch information
saito-hideki committed Dec 17, 2014
2 parents 1895bd8 + 166e120 commit c8037f3
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 138 deletions.
93 changes: 2 additions & 91 deletions playbooks/openstack/create_vm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,97 +4,8 @@
# Required: ansible-v1.8 or later and openrc
#
- hosts: localhost

vars:
auth:
url: "{{ lookup('env', 'OS_AUTH_URL') }}"
region_name: "{{ lookup('env', 'OS_REGION_NAME') }}"
tenant_name: "{{ lookup('env', 'OS_TENANT_NAME') }}"
username: "{{ lookup('env', 'OS_USERNAME') }}"
password: "{{ lookup('env', 'OS_PASSWORD') }}"
networks:
os_dmz_net: "{{ lookup('env', 'OS_DMZ_NET') }}"
os_app_net: "{{ lookup('env', 'OS_APP_NET') }}"
os_dbs_net: "{{ lookup('env', 'OS_DBS_NET') }}"
os_ext_net_list:
- "Ext-Net"
spec:
web:
flavor_ram: 1024
flavor_name: "standard.xsmall"
image_name: "centos-base"
key_name: "key-for-internal"
secgroups: "sg-all-from-console,sg-web-from-internet,sg-all-from-app-net"
availability_zone: "az1"
networks:
- net-id: "{{ networks.os_dmz_net }}"
- net-id: "{{ networks.os_app_net }}"
floating_ip: yes
app:
flavor_ram: 1024
flavor_name: "standard.xsmall"
image_name: "centos-base"
key_name: "key-for-internal"
secgroups: "sg-all-from-console,sg-all-from-app-net,sg-all-from-dbs-net"
availability_zone: "az1"
networks:
- net-id: "{{ networks.os_dmz_net }}"
- net-id: "{{ networks.os_app_net }}"
- net-id: "{{ networks.os_dbs_net }}"
floating_ip: no
dbs:
flavor_ram: 1024
flavor_name: "standard.xsmall"
image_name: "centos-base"
key_name: "key-for-internal"
secgroups: "sg-all-from-console,sg-all-from-dbs-net"
availability_zone: "az1"
networks:
- net-id: "{{ networks.os_dmz_net }}"
- net-id: "{{ networks.os_dbs_net }}"
floating_ip: no
tasks:
- name: ansible_python_interpreter setup
set_fact: ansible_python_interpreter="{{ lookup('pipe', 'which python') }}"
- name: get uuid for generate hostname
command: /usr/bin/uuidgen
register: result_uuid
when: target in ["web", "app", "dbs"]
- name: create {{ target }}-server on nova-compute with floating_ip
nova_compute:
state: present
auth_url: "{{ auth.url }}"
region_name: "{{ auth.region_name }}"
login_tenant_name: "{{ auth.tenant_name }}"
login_username: "{{ auth.username }}"
login_password: "{{ auth.password }}"
availability_zone: "{{ spec[target].availability_zone }}"
flavor_ram: "{{ spec[target].flavor_ram }}"
flavor_include: "{{ spec[target].flavor_name }}"
floating_ip_pools: "{{ networks.os_ext_net_list }}"
image_name: "{{ spec[target].image_name }}"
key_name: "{{ spec[target].key_name }}"
name: "{{ target }}-{{ result_uuid.stdout }}"
nics: "{{ spec[target].networks }}"
security_groups: "{{ spec[target].secgroups }}"
when: (target in ["web","app","dbs"]) and (spec[target].floating_ip)
- name: create {{ target }}-server on nova-compute without floating_ip
nova_compute:
state: present
auth_url: "{{ auth.url }}"
region_name: "{{ auth.region_name }}"
login_tenant_name: "{{ auth.tenant_name }}"
login_username: "{{ auth.username }}"
login_password: "{{ auth.password }}"
availability_zone: "{{ spec[target].availability_zone }}"
flavor_ram: "{{ spec[target].flavor_ram }}"
flavor_include: "{{ spec[target].flavor_name }}"
image_name: "{{ spec[target].image_name }}"
key_name: "{{ spec[target].key_name }}"
name: "{{ target }}-{{ result_uuid.stdout }}"
nics: "{{ spec[target].networks }}"
security_groups: "{{ spec[target].secgroups }}"
when: (target in ["web","app","dbs"]) and (not spec[target].floating_ip)
roles:
- create_vm
#
# [EOF]
#
49 changes: 2 additions & 47 deletions playbooks/openstack/install_sns.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,8 @@

remote_user: root

vars:
spec:
web:
app_name: "sample-app"
project_url: "https://github.com/josug-book1-materials/sample-app.git"
init_script: "install_web.sh"
startup_script: "web.init.sh"
init_script_version: "v1.0"
app:
app_name: "sample-app"
project_url: "https://github.com/josug-book1-materials/sample-app.git"
init_script: "install_rest.sh"
startup_script: "rest.init.sh"
init_script_version: "v1.0"
dbs:
app_name: "sample-app"
project_url: "https://github.com/josug-book1-materials/sample-app.git"
init_script: "install_db.sh"
init_script_version: "v1.0"

tasks:
- name: change the timezone
command: cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
when: target in ["web", "app", "dbs"]
- name: checkout app from github
git:
repo: "{{ spec[target].project_url }}"
version: "{{ spec[target].init_script_version }}"
dest: /root/{{ spec[target].app_name }}
when: target in ["web", "app", "dbs"]
- name: execute install script
raw: sh /root/{{ spec[target].app_name }}/server-setup/{{ spec[target].init_script }}
when: target in ["web", "app", "dbs"]
- name: copy endpoint.conf to web and app server
template:
src: endpoint.conf.j2
dest: /root/{{ spec[target].app_name }}/endpoint.conf
owner: root
group: root
mode: 0644
notify: startup service
when: target in ["web", "app"]

handlers:
- name: startup service
shell: nohup /bin/bash /root/{{ spec[target].app_name }}/server-setup/{{ spec[target].startup_script }} start

roles:
- install_sns
#
# [EOF]
#
48 changes: 48 additions & 0 deletions playbooks/openstack/roles/create_vm/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
- name: ansible_python_interpreter setup
set_fact: ansible_python_interpreter="{{ lookup('pipe', 'which python') }}"

- name: get uuid for generate hostname
command: /usr/bin/uuidgen
register: result_uuid
when: target in ["web", "app", "dbs"]

- name: create {{ target }}-server on nova-compute with floating_ip
nova_compute:
state: present
auth_url: "{{ auth.url }}"
region_name: "{{ auth.region_name }}"
login_tenant_name: "{{ auth.tenant_name }}"
login_username: "{{ auth.username }}"
login_password: "{{ auth.password }}"
availability_zone: "{{ spec[target].availability_zone }}"
flavor_ram: "{{ spec[target].flavor_ram }}"
flavor_include: "{{ spec[target].flavor_name }}"
floating_ip_pools: "{{ networks.os_ext_net_list }}"
image_name: "{{ spec[target].image_name }}"
key_name: "{{ spec[target].key_name }}"
name: "{{ target }}-{{ result_uuid.stdout }}"
nics: "{{ spec[target].networks }}"
security_groups: "{{ spec[target].secgroups }}"
when: (target == "web") and (spec[target].floating_ip)

- name: create {{ target }}-server on nova-compute without floating_ip
nova_compute:
state: present
auth_url: "{{ auth.url }}"
region_name: "{{ auth.region_name }}"
login_tenant_name: "{{ auth.tenant_name }}"
login_username: "{{ auth.username }}"
login_password: "{{ auth.password }}"
availability_zone: "{{ spec[target].availability_zone }}"
flavor_ram: "{{ spec[target].flavor_ram }}"
flavor_include: "{{ spec[target].flavor_name }}"
image_name: "{{ spec[target].image_name }}"
key_name: "{{ spec[target].key_name }}"
name: "{{ target }}-{{ result_uuid.stdout }}"
nics: "{{ spec[target].networks }}"
security_groups: "{{ spec[target].secgroups }}"
when: (target in ["app","dbs"]) and (not spec[target].floating_ip)
#
# [EOF]
#
52 changes: 52 additions & 0 deletions playbooks/openstack/roles/create_vm/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
auth:
url: "{{ lookup('env', 'OS_AUTH_URL') }}"
region_name: "{{ lookup('env', 'OS_REGION_NAME') }}"
tenant_name: "{{ lookup('env', 'OS_TENANT_NAME') }}"
username: "{{ lookup('env', 'OS_USERNAME') }}"
password: "{{ lookup('env', 'OS_PASSWORD') }}"
networks:
os_dmz_net: "{{ lookup('env', 'OS_DMZ_NET') }}"
os_app_net: "{{ lookup('env', 'OS_APP_NET') }}"
os_dbs_net: "{{ lookup('env', 'OS_DBS_NET') }}"
os_ext_net_list:
- "Ext-Net"
spec:
web:
flavor_ram: 1024
flavor_name: "standard.xsmall"
image_name: "centos-base"
key_name: "key-for-internal"
secgroups: "sg-all-from-console,sg-web-from-internet,sg-all-from-app-net"
availability_zone: "az1"
networks:
- net-id: "{{ networks.os_dmz_net }}"
- net-id: "{{ networks.os_app_net }}"
floating_ip: yes
app:
flavor_ram: 1024
flavor_name: "standard.xsmall"
image_name: "centos-base"
key_name: "key-for-internal"
secgroups: "sg-all-from-console,sg-all-from-app-net,sg-all-from-dbs-net"
availability_zone: "az1"
networks:
- net-id: "{{ networks.os_dmz_net }}"
- net-id: "{{ networks.os_app_net }}"
- net-id: "{{ networks.os_dbs_net }}"
floating_ip: no
dbs:
flavor_ram: 1024
flavor_name: "standard.xsmall"
image_name: "centos-base"
key_name: "key-for-internal"
secgroups: "sg-all-from-console,sg-all-from-dbs-net"
availability_zone: "az1"
networks:
- net-id: "{{ networks.os_dmz_net }}"
- net-id: "{{ networks.os_dbs_net }}"
floating_ip: no

#
# [EOF]
#
7 changes: 7 additions & 0 deletions playbooks/openstack/roles/install_sns/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: startup service
shell: nohup /bin/bash /root/{{ spec[target].app_name }}/server-setup/{{ spec[target].startup_script }} start

#
# [EOF]
#
29 changes: 29 additions & 0 deletions playbooks/openstack/roles/install_sns/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
- name: change the timezone
command: cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
when: target in ["web", "app", "dbs"]

- name: checkout app from github
git:
repo: "{{ spec[target].project_url }}"
version: "{{ spec[target].init_script_version }}"
dest: /root/{{ spec[target].app_name }}
when: target in ["web", "app", "dbs"]

- name: execute install script
raw: sh /root/{{ spec[target].app_name }}/server-setup/{{ spec[target].init_script }}
when: target in ["web", "app", "dbs"]

- name: copy endpoint.conf to web and app server
template:
src: endpoint.conf.j2
dest: /root/{{ spec[target].app_name }}/endpoint.conf
owner: root
group: root
mode: 0644
notify: startup service
when: target in ["web", "app"]

#
# [EOF]
#
File renamed without changes.
23 changes: 23 additions & 0 deletions playbooks/openstack/roles/install_sns/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
spec:
web:
app_name: "sample-app"
project_url: "https://github.com/josug-book1-materials/sample-app.git"
init_script: "install_web.sh"
startup_script: "web.init.sh"
init_script_version: "v1.0"
app:
app_name: "sample-app"
project_url: "https://github.com/josug-book1-materials/sample-app.git"
init_script: "install_rest.sh"
startup_script: "rest.init.sh"
init_script_version: "v1.0"
dbs:
app_name: "sample-app"
project_url: "https://github.com/josug-book1-materials/sample-app.git"
init_script: "install_db.sh"
init_script_version: "v1.0"

#
# [EOF]
#

0 comments on commit c8037f3

Please sign in to comment.