Skip to content

Instantly share code, notes, and snippets.

@Spredzy
Created June 14, 2017 12:18
Show Gist options
  • Save Spredzy/60b7ffb3366956acf238b4bb8a701368 to your computer and use it in GitHub Desktop.
Save Spredzy/60b7ffb3366956acf238b4bb8a701368 to your computer and use it in GitHub Desktop.
# Initial Step:
#
# Schedule a new job giving a specific topic and specifying the remote CI.
# The return of this action contains all the data associated with the job,
# we hence register those data for later consumptions
#
- hosts: localhost
tasks:
- name: Schedule a new job
dci_job:
topic: 'OSP10'
remoteci: lab-arnX
register: job_informations
# New state
#
# User is free to do whaterver she needs before entering pre-run state.
# Usually this is used to sync the components the job is relying on.
#
- name: 'New state commands'
hosts: localhost
become: true
become_flags: '-E'
vars:
dci_status: 'new'
local_repo_dir: '/var/www/html/repos'
tasks:
- block:
- name: Ensure httpd is installed
package:
name: httpd
- name: Ensure the repository directory exist
file:
path: '{{ local_repo_dir }}'
state: directory
- name: Check for existing component file
stat:
path: '{{ local_repo_dir }}/{{ item["id"] }}.tar'
with_items: '{{ job_informations["components"] }}'
register: components
- name: Retrieve component
dci_component:
id: '{{ item.item["id"] }}'
dest: '{{ local_repo_dir }}/{{ item.item["id"] }}.tar'
with_items: '{{ components.results }}'
when: not item.stat.exists
- name: Ensure proper directories are created
file:
path: '{{ local_repo_dir }}/{{ job_informations["job_id"] }}'
state: directory
- name: Unarchive component
unarchive:
src: '{{ local_repo_dir }}/{{ item.item["id"] }}.tar'
dest: '{{ local_repo_dir }}/{{ job_informations["job_id"] }}'
remote_src: True
with_items: '{{ components.results }}'
- name: Clean yum repo
file:
path: '{{ local_repo_dir }}/dci.repo'
state: absent
- name: Create yum repo
yum_repository:
name: '{{ item.item["canonical_project_name"] }}'
description: '{{ item.item["canonical_project_name"] }}'
baseurl: 'http://{{ ansible_default_ipv4.address }}/dci/{{ job_informations["job_id"] }}/{{ item.item["canonical_project_name"] }}'
gpgcheck: no
enabled: yes
file: '{{ local_repo_dir }}/dci'
with_items: '{{ components.results }}'
- name: Ensure httpd is running
service:
name: httpd
state: started
rescue:
- name: Fail properly
fail:
msg: 'Something went wrong with the installation'
# Pre-run state
#
# User is free to do whaterver she needs before entering pre-run state.
# Usually this is used to spawn the undercloud vm
#
- name: 'Pre-run state commands'
hosts: localhost
vars:
dci_status: 'pre-run'
tasks:
- block:
- name: echo 'Pre-run'
shell: echo 'pre-run'
rescue:
- name: Fail properly
fail:
msg: 'Something went wrong with the installation'
# Running state
#
# User is free to do whaterver she needs before entering running state.
# Usually this is used to provision the undercloud and the overcloud
#
- name: 'Running state commands'
hosts: localhost
vars:
dci_status: 'running'
tasks:
- block:
- name: echo 'Running'
shell: echo 'Running'
rescue:
- name: Fail properly
fail:
msg: 'Something went wrong with the installation'
# Post-run state
#
# User is free to do whaterver she needs before entering post-run state.
# Usually this is used to run tests on the overcloud
#
- name: 'Post-run state commands'
hosts: localhost
vars:
dci_status: 'post-run'
dci_comment: 'Post-run state commands'
tasks:
- block:
- name: echo 'Post-run'
shell: echo 'Post-run'
rescue:
- name: Fail properly
fail:
msg: 'Something went wrong with the installation'
# Success state
#
# User is free to do whaterver she needs before entering pre-run state.
# Usually this is used to teardown the plateform
#
- name: 'Success state commands'
hosts: localhost
vars:
dci_status: 'success'
tasks:
- name: echo 'Success'
shell: echo 'Succes'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment