mirror of
https://github.com/kasmtech/ansible.git
synced 2026-07-17 16:46:36 +00:00
203 lines
5.2 KiB
YAML
203 lines
5.2 KiB
YAML
- include_tasks:
|
|
file: default_credentials.yml
|
|
|
|
- name: Check if Kasm is installed
|
|
stat:
|
|
path: /opt/kasm/current
|
|
register: kasm_path
|
|
|
|
- set_fact:
|
|
kasm_installed: "{{ kasm_path.stat.exists }}"
|
|
|
|
- set_fact:
|
|
web_ip: "{{ hostvars[group_names[0] + '_web_' + inventory_hostname.split('_')[2]].ansible_default_ipv4.address }}"
|
|
# IP of the host that ansible is being ran against
|
|
target_ip: "{{ ansible_default_ipv4.address }}"
|
|
when: not default_web
|
|
|
|
- set_fact:
|
|
web_ip: "{{ hostvars[group_names[0] + '_web_' + default_web|string].ansible_default_ipv4.address }}"
|
|
# IP of the host that ansible is being ran against
|
|
target_ip: "{{ ansible_default_ipv4.address }}"
|
|
when: default_web
|
|
|
|
- set_fact:
|
|
db_ip: "{{ hostvars['zone1_db_1'].ansible_default_ipv4.address }}"
|
|
when: not database_hostname
|
|
|
|
- set_fact:
|
|
db_ip: "{{ database_hostname }}"
|
|
when: database_hostname
|
|
|
|
- set_fact:
|
|
redis_ip: "{{ hostvars['zone1_db_1'].ansible_default_ipv4.address }}"
|
|
when: not redis_hostname
|
|
|
|
- set_fact:
|
|
redis_ip: "{{ redis_hostname }}"
|
|
when: redis_hostname
|
|
|
|
- name: Override manager hostname if configured
|
|
set_fact:
|
|
web_ip: "{{ manager_hostname }}"
|
|
when: manager_hostname is defined
|
|
|
|
- name: Check if kasm swapfile exists
|
|
stat:
|
|
path: /mnt/kasm.swap
|
|
register: kasm_swapfile
|
|
when:
|
|
- "'agent' in group_names[1].split('_')"
|
|
|
|
- name: Get current swapsize in bytes
|
|
# Meminfo outputs in Kb for some reason so we convert to bytes
|
|
shell: cat /proc/meminfo | grep SwapTotal | awk '{print $2 * 1024}'
|
|
register: current_swap_size
|
|
changed_when: false
|
|
when:
|
|
- "'agent' in group_names[1].split('_')"
|
|
|
|
- set_fact:
|
|
# We only want to make a swapfile large enough to make up the difference between
|
|
# the current swapsize and our desired size.
|
|
new_swap_size: "{{ desired_swap_size | human_to_bytes - current_swap_size.stdout | int }}"
|
|
when:
|
|
- "'agent' in group_names[1].split('_')"
|
|
|
|
- debug:
|
|
var: new_swap_size
|
|
when:
|
|
- "'agent' in group_names[1].split('_')"
|
|
|
|
- name: Run swap tasks
|
|
include_tasks:
|
|
file: mkswap.yml
|
|
when:
|
|
- "'agent' in group_names[1].split('_')"
|
|
- new_swap_size | int > 0
|
|
- not kasm_swapfile.stat.exists
|
|
|
|
- name: Create temporary directory
|
|
tempfile:
|
|
state: directory
|
|
register: tempdir
|
|
|
|
# Debian 10 doesn't ship with the ca-certificates package installed by default
|
|
# installing curl is portable to to ensure that ca-certificates is installed
|
|
- name: Ensure we have curl installed
|
|
package:
|
|
name: curl
|
|
state: present
|
|
become: true
|
|
|
|
- include_tasks:
|
|
file: copy_installer.yml
|
|
when:
|
|
- not kasm_installed
|
|
|
|
- name: Add additional zones tasks
|
|
include_tasks:
|
|
file: add_zones.yml
|
|
when:
|
|
- not kasm_installed
|
|
|
|
- name: Run Kasm db install tasks
|
|
include_tasks:
|
|
file: db_install.yml
|
|
when:
|
|
- "'db' in group_names[1].split('_')"
|
|
- not kasm_installed
|
|
|
|
- name: Run remote db init tasks
|
|
include_tasks:
|
|
file: remote_db_init.yml
|
|
when:
|
|
- init_remote_db
|
|
- database_hostname
|
|
- "'web' in group_names[1].split('_')"
|
|
- not kasm_installed
|
|
|
|
- name: Run Kasm web install tasks
|
|
include_tasks:
|
|
file: web_install.yml
|
|
when:
|
|
- "'web' in group_names[1].split('_')"
|
|
- not kasm_installed
|
|
|
|
- name: Run Kasm agent install tasks
|
|
include_tasks:
|
|
file: agent_install.yml
|
|
when:
|
|
- "'agent' in group_names[1].split('_')"
|
|
- not kasm_installed
|
|
|
|
- name: Run Kasm guac install tasks
|
|
include_tasks:
|
|
file: guac_install.yml
|
|
when:
|
|
- "'guac' in group_names[1].split('_')"
|
|
- not kasm_installed
|
|
|
|
- name: Run Kasm proxy install tasks
|
|
include_tasks:
|
|
file: proxy_install.yml
|
|
when:
|
|
- "'proxy' in group_names[1].split('_')"
|
|
- not kasm_installed
|
|
|
|
- name: enable the docker service to run at boot
|
|
service:
|
|
name: docker
|
|
enabled: true
|
|
become: true
|
|
when: start_docker_on_boot
|
|
|
|
- name: Delete temporary directory
|
|
file:
|
|
path: "{{ tempdir.path }}"
|
|
state: absent
|
|
become: true
|
|
|
|
- name: Print credentials
|
|
debug:
|
|
msg:
|
|
- "Database Password: {{ database_password }}"
|
|
- "Redis Password: {{ redis_password }}"
|
|
- "Manager Token: {{ manager_token }}"
|
|
- "Registration Token: {{ registration_token }}"
|
|
- "user@kasm.local password: {{ user_password }}"
|
|
- "admin@kasm.local password: {{ admin_password }}"
|
|
run_once: true
|
|
|
|
- name: Write credentials to inventory
|
|
run_once: true
|
|
delegate_to: localhost
|
|
ansible.builtin.template:
|
|
src: "{{ inventory_file }}"
|
|
dest: "{{ inventory_file }}"
|
|
|
|
- name: Set credentials to active
|
|
run_once: true
|
|
delegate_to: localhost
|
|
ansible.builtin.replace:
|
|
dest: "{{ inventory_file }}"
|
|
regexp: "{{ item.from }}"
|
|
replace: "{{ item.to }}"
|
|
loop:
|
|
- {from: "#user_password", to: "user_password"}
|
|
- {from: "#admin_password", to: "admin_password"}
|
|
- {from: "#database_password", to: "database_password"}
|
|
- {from: "#redis_password", to: "redis_password"}
|
|
- {from: "#manager_token", to: "manager_token"}
|
|
- {from: "#registration_token", to: "registration_token"}
|
|
|
|
- name: Turn off remote db init
|
|
run_once: true
|
|
delegate_to: localhost
|
|
ansible.builtin.replace:
|
|
dest: "{{ inventory_file }}"
|
|
regexp: "init_remote_db: true"
|
|
replace: "init_remote_db: false"
|
|
when:
|
|
- init_remote_db
|
|
- database_hostname
|