From f849e486117c489b4d5413e5776a7d36e7e55fdd Mon Sep 17 00:00:00 2001 From: Kevin Fenzi Date: Wed, 13 May 2015 20:34:50 +0000 Subject: [PATCH] First untested cut at a temp/transient cloud playbook for new cloud. --- playbooks/temp_cloud_instance.yml | 70 +++++++++++++++++++++++++++++++ tasks/transient_cloud_new.yml | 43 +++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 playbooks/temp_cloud_instance.yml create mode 100644 tasks/transient_cloud_new.yml diff --git a/playbooks/temp_cloud_instance.yml b/playbooks/temp_cloud_instance.yml new file mode 100644 index 0000000000..ce43adde32 --- /dev/null +++ b/playbooks/temp_cloud_instance.yml @@ -0,0 +1,70 @@ +# setup a transient fedora instance +# optionally can take -e "name=something image=imagename public_ips=public_ip root_auth_users='user1 user2 user3'" + +- name: check/create instance + hosts: lockbox01.phx2.fedoraproject.org + user: root + gather_facts: False + + vars_files: + - /srv/web/infra/ansible/vars/global.yml + - /srv/private/ansible/vars.yml + - /srv/web/infra/ansible/vars/fedora-cloud.yml + - /srv/private/ansible/files/openstack/passwords.yml + vars: + - keypair: fedora-admin-20130801 + - image: {{ centos70_x86_64 }} + - instance_type: m1.small + - security_group: web-80-anywhere-persistent,web-443-anywhere-persistent,ssh-anywhere-persistent,default + - region: nova + - auth_url: "{{os_auth_url}}" + - login_username: "admin" + - login_password: "{{ADMIN_PASS}}" + - login_tenant_name: transient + - image_id: "{{ image|image_name_to_id('admin', ADMIN_PASS, inventory_tenant, os_auth_url) }}" + - nics: + - net-id: "28db7265-fb78-4937-bfe3-9c8a9b959c30" + - floating_ips: + - "{{public_ip}}" + + tasks: + - name: fail when name is not provided + fail: msg="Please specify the name of the instance" + when: name is not defined + + - name: fail when public_ip is not provided + fail: msg="Please specify the public_ip for the instance" + when: public_ip is not defined + + - include: "{{ tasks }}/transient_cloud_new.yml" + +- name: provision instance + hosts: tmp_just_created + gather_facts: True + user: fedora + sudo: True + + vars_files: + - /srv/web/infra/ansible/vars/global.yml + - "/srv/private/ansible/vars.yml" + - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml + + tasks: + - name: install cloud-utils + yum: pkg=cloud-utils state=present + + - name: growpart /dev/vda1 partition (/) to full size + action: command growpart /dev/vda 1 + register: growpart + always_run: true + changed_when: "growpart.rc != 1" + failed_when: growpart.rc == 2 + + - name: resize the /dev/vda 1 fs + action: command xfs_growfs /dev/vda1 + when: growpart.rc == 0 + + - include: "{{ tasks }}/cloud_setup_basic.yml" + + handlers: + - include: "{{ handlers }}/restart_services.yml" diff --git a/tasks/transient_cloud_new.yml b/tasks/transient_cloud_new.yml new file mode 100644 index 0000000000..e5c1a72c1d --- /dev/null +++ b/tasks/transient_cloud_new.yml @@ -0,0 +1,43 @@ +# New tasks to spin up instance in https://fed-cloud09.cloud.fedoraproject.org + +- name: check it out + local_action: shell nc -d -z -w 5 {{ inventory_hostname }} 22 >>/dev/null + register: host_is_up + ignore_errors: true + +- name: spin UP VM using nova_compute + sudo: False + local_action: + module: nova_compute + auth_url: "{{os_auth_url}}" + login_username: "admin" + login_password: "{{ADMIN_PASS}}" + login_tenant_name: "{{inventory_tenant}}" + name: "{{inventory_instance_name}}" + image_id: "{{ image|image_name_to_id('admin', ADMIN_PASS, inventory_tenant, os_auth_url) }}" + wait_for: 300 + flavor_id: "{{ instance_type|flavor_name_to_id('admin', ADMIN_PASS, inventory_tenant, os_auth_url) }}" + security_groups: "{{security_group}}" + key_name: "{{ keypair }}" + nics: "{{ cloud_networks }}" + floating_ips: + - "{{public_ip}}" + register: nova_result + when: host_is_up|failed + +- name: add it to the special group + local_action: add_host hostname=public_ip groupname=tmp_just_created + +#- name: mail off about where it is +# local_action: mail to=sysadmin-main-members@fedoraproject.org from=ansible-create@fedoraproject.org subject={{ public_ip }} msg="cloud instance created on {{ public_ip }}\n {{ hostbase }} {{ root_auth_users }} " +# + +- name: wait for he host to be hot + local_action: wait_for host={{ public_ip }} port=22 delay=1 timeout=600 + when: host_is_up|failed + +# SSH is up and running, however cloud-init still did not deployed ssh keypair +# we have to wait some time. 10 sec is usually enough, but not always. +- name: waiting for cloud-init + pause: seconds=30 + when: host_is_up|failed