Skip to content

Instantly share code, notes, and snippets.

@lae
Last active April 17, 2018 19:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lae/94e81329f1ee98ff02a59f03fa28f00f to your computer and use it in GitHub Desktop.
Save lae/94e81329f1ee98ff02a59f03fa28f00f to your computer and use it in GitHub Desktop.
dr-provision ansible role (tasks file only)
---
# tasks file for provision
- name: Install necessary packages for DR Provision
apt:
name: "{{ item }}"
state: latest
update_cache: yes
with_items:
- unzip
- p7zip-full
- bsdtar
- jq
- git
- name: Create directories for DR Provision
file:
path: "{{ item }}"
state: directory
with_items:
- "{{ provision_download_directory }}"
- "{{ provision_content_directory }}"
- name: Fetch DR Provision artifacts
get_url:
url: "https://github.com/digitalrebar/provision/releases/download/{{ provision_release_tag }}/dr-provision.zip"
dest: "{{ provision_download_directory }}/dr-provision.zip"
- name: Extract DR Provision artifacts
unarchive:
src: "{{ provision_download_directory }}/dr-provision.zip"
dest: "{{ provision_download_directory }}"
remote_src: yes
- name: Install DR Provision binaries
copy:
src: "{{ provision_download_directory }}/bin/linux/amd64/{{ item }}"
dest: "/usr/local/bin/{{ item }}"
mode: 0755
remote_src: yes
with_items:
- dr-provision
- drpcli
notify:
- restart dr-provision
- name: Install systemd unit file for DR Provision
copy:
src: "{{ provision_download_directory }}/assets/startup/dr-provision.service"
dest: "/etc/systemd/system/dr-provision.service"
remote_src: yes
notify:
- reload systemd unit files
- name: Start and enable DR Provision
systemd:
name: dr-provision
state: started
enabled: yes
daemon_reload: yes
- name: Clone provision-content
git:
repo: "{{ provision_content_repo }}"
dest: "{{ provision_content_directory }}"
- name: Install boot environments
shell: "drpcli bootenvs install bootenvs/{{ item }}.yml"
args:
chdir: "{{ provision_content_directory }}"
creates: "/var/lib/dr-provision/bootenvs/{{ item }}.json"
with_items: "{{ provision_content_bootenvs }}"
- name: Configure DR Provision preferences
copy:
content: '{"Name":"{{ item.key }}","Val":"{{ item.value }}"}'
dest: "/var/lib/dr-provision/preferences/{{ item.key }}.json"
with_dict: "{{ provision_preferences }}"
notify:
- restart dr-provision
- name: Configure DR Provision API user
shell: "drpcli users create {{ provision_api_user }}"
args:
creates: "/var/lib/dr-provision/users/{{ provision_api_user }}.json"
- name: Update DR Provision API password
shell: "drpcli -U {{ provision_api_user }} -P \"{{ provision_api_password }}\" prefs list >/dev/null 2>&1 && exit 0 || drpcli users password {{ provision_api_user }} \"{{ provision_api_password }}\" && exit 114"
register: provision_password_update
changed_when: provision_password_update.rc == 114
failed_when: provision_password_update.rc != 114 and provision_password_update.rc != 0
- name: Update shell environment with DR Provision API credentials
copy:
content: "#!/bin/bash\nexport RS_KEY=\"{{ provision_api_user }}:{{ provision_api_password }}\""
dest: "/etc/profile.d/dr-provision.sh"
mode: 0755
- name: Remove default rocketskates user if different api_user is set
shell: "drpcli users destroy rocketskates"
args:
removes: "/var/lib/dr-provision/users/rocketskates.json"
- name: Add drpcli autocomplete definitions
shell: "drpcli autocomplete /etc/bash_completion.d/drpcli"
args:
creates: "/etc/bash_completion.d/drpcli"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment