diff options
| author | Carlos Konstanski <ckonstanski@pippiandcarlos.com> | 2017-11-13 16:50:55 -0700 |
|---|---|---|
| committer | Carlos Konstanski <ckonstanski@pippiandcarlos.com> | 2017-11-13 16:50:55 -0700 |
| commit | ffa2a169ea98fb54a29d90ca158059e79e2816ba (patch) | |
| tree | 018461d031b71178fa48b9672d8e39bac4de1270 /playbooks | |
initial commit
Diffstat (limited to 'playbooks')
| -rw-r--r-- | playbooks/ansible.yaml | 52 | ||||
| -rw-r--r-- | playbooks/docker.yaml | 88 | ||||
| -rw-r--r-- | playbooks/docker_compose.yaml | 22 | ||||
| -rw-r--r-- | playbooks/docker_registry.yaml | 65 | ||||
| -rw-r--r-- | playbooks/gradle.yaml | 53 | ||||
| -rw-r--r-- | playbooks/haveged.yaml | 36 | ||||
| -rw-r--r-- | playbooks/install_docker_registry.yaml | 4 | ||||
| -rw-r--r-- | playbooks/install_openbook.yaml | 5 | ||||
| -rw-r--r-- | playbooks/install_openbook_docker_slave.yaml | 9 | ||||
| -rw-r--r-- | playbooks/jenkins_user.yaml | 15 | ||||
| -rw-r--r-- | playbooks/mysql_client.yaml | 60 | ||||
| -rw-r--r-- | playbooks/openbook.yaml | 212 | ||||
| -rw-r--r-- | playbooks/openjdk.yaml | 59 | ||||
| -rw-r--r-- | playbooks/salt.yaml | 96 | ||||
| -rw-r--r-- | playbooks/ssh_keys.yaml | 39 | ||||
| -rw-r--r-- | playbooks/stop_start_openbook.yaml | 28 |
16 files changed, 843 insertions, 0 deletions
diff --git a/playbooks/ansible.yaml b/playbooks/ansible.yaml new file mode 100644 index 0000000..94850fc --- /dev/null +++ b/playbooks/ansible.yaml @@ -0,0 +1,52 @@ +--- +- name: "Install ansible" + hosts: target + tasks: + - name: "Add ansible PPA" + apt_repository: + repo: ppa:ansible/ansible + state: present + + - name: "Update apt" + apt: + update_cache: yes + when: ansible_distribution == "Ubuntu" + + - name: "Install ansible package" + apt: + pkg: "{{ item }}" + state: present + with_items: + - ansible + when: ansible_distribution == "Ubuntu" + + - name: "Update yum cache" + yum: + update_cache: yes + when: ansible_distribution == "RedHat" or ansible_distribution == "CentOS" + + - name: "Install ansible package" + yum: + name: "{{ item }}" + state: present + with_items: + - ansible + when: ansible_distribution == "RedHat" or ansible_distribution == "CentOS" + + - name: "Install ansible package" + portage: + name: "{{ item }}" + state: present + with_items: + - app-admin/ansible + when: ansible_distribution == "Gentoo" + + - name: "Configure ansible" + copy: + src: "../files/{{ item.src }}" + dest: "{{ item.dest }}" + mode: "{{ item.mode }}" + owner: root + group: root + with_items: + - { src: ansible.cfg, dest: /etc/ansible/ansible.cfg, mode: "0644" } diff --git a/playbooks/docker.yaml b/playbooks/docker.yaml new file mode 100644 index 0000000..9ac5499 --- /dev/null +++ b/playbooks/docker.yaml @@ -0,0 +1,88 @@ +--- +- name: "Install docker" + hosts: target + tasks: + - name: "Install kernel extras" + apt: + pkg: "{{ item }}" + state: present + with_items: + - "linux-image-extra-{{ ansible_kernel }}" + - linux-image-extra-virtual + - apt-transport-https + - ca-certificates + - software-properties-common + when: ansible_distribution == "Ubuntu" + + - name: "Install docker apt key" + shell: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - + when: ansible_distribution == "Ubuntu" + + - name: "Configure docker.list" + copy: + src: "../files/{{ item }}" + dest: "/etc/apt/sources.list.d/{{ item }}" + mode: 0644 + owner: root + group: root + with_items: + - docker.list + when: ansible_distribution == "Ubuntu" + + - name: "Update apt" + apt: + update_cache: yes + when: ansible_distribution == "Ubuntu" + + - name: "Install docker packages" + apt: + pkg: "{{ item }}" + state: present + with_items: + - docker-ce + when: ansible_distribution == "Ubuntu" + + - name: "Install required packages" + yum: + name: "{{ item }}" + state: present + with_items: + - yum-utils + - device-mapper-persistent-data + - lvm2 + when: ansible_distribution == "RedHat" or ansible_distribution == "CentOS" + + - name: "Add docker repository" + shell: yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo + when: ansible_distribution == "RedHat" or ansible_distribution == "CentOS" + + - name: "Update yum cache" + yum: + update_cache: yes + when: ansible_distribution == "RedHat" or ansible_distribution == "CentOS" + + - name: "Install required packages" + yum: + name: "{{ item }}" + state: present + with_items: + - docker-ce + when: ansible_distribution == "RedHat" or ansible_distribution == "CentOS" + + - name: "Install docker" + portage: + package: "{{ item }}" + update: yes + changed_use: yes + with_items: + - app-emulation/docker + when: ansible_distribution == "Gentoo" + + - name: "Enable docker" + service: + name: "{{ item.name }}" + enabled: yes + state: started + runlevel: "{{ item.runlevel }}" + with_items: + - { name: docker, runlevel: default } diff --git a/playbooks/docker_compose.yaml b/playbooks/docker_compose.yaml new file mode 100644 index 0000000..8333a4b --- /dev/null +++ b/playbooks/docker_compose.yaml @@ -0,0 +1,22 @@ +--- +- name: "Install docker-compose" + hosts: target + tasks: + - name: "Install packages" + apt: + pkg: "{{ item }}" + state: present + with_items: + - docker-compose + - apache2-utils + when: ansible_distribution == "Ubuntu" + + - name: "Install packsges" + portage: + package: "{{ item }}" + update: yes + changed_use: yes + with_items: + - app-emulation/docker-compose + - app-admin/apache-tools + when: ansible_distribution == "Gentoo" diff --git a/playbooks/docker_registry.yaml b/playbooks/docker_registry.yaml new file mode 100644 index 0000000..20dfb73 --- /dev/null +++ b/playbooks/docker_registry.yaml @@ -0,0 +1,65 @@ +--- +- name: "Install docker-registry" + hosts: target + tasks: + - name: "Create docker-registry directories" + file: + path: "{{ item.path }}" + state: directory + mode: "{{ item.mode }}" + with_items: + - { path: /root/docker-registry/nginx, mode: "0755" } + - { path: /root/docker-registry/data, mode: "0755" } + + - name: "Create docker-registry files" + template: + src: "../templates/{{ item.src }}" + dest: "{{ item.dest }}" + mode: "{{ item.mode }}" + owner: root + group: root + with_items: + - { src: registry.conf, dest: /root/docker-registry/nginx/registry.conf, mode: "0644" } + + - name: "Create docker-registry files" + copy: + src: "../files/{{ item.src }}" + dest: "{{ item.dest }}" + mode: "{{ item.mode }}" + owner: root + group: root + with_items: + - { src: docker-compose.yaml, dest: /root/docker-registry/docker-compose.yaml, mode: "0644" } + + - name: "Copy SSL certs into nginx directory" + shell: | + cp "/etc/ssl/certs/{{ cn }}.crt" /root/docker-registry/nginx/ + cp "/etc/ssl/certs/{{ cn }}.ca" /root/docker-registry/nginx/ + cp "/etc/ssl/private/{{ cn }}.key" /root/docker-registry/nginx/ + when: ansible_distribution == "Ubuntu" or ansible_distribution == "Gentoo" + + - name: "Create password file" + shell: htpasswd -c -b -s /root/docker-registry/nginx/registry.password '{{ username }}' '{{ password }}' + + - name: "Install init script" + copy: + src: ../files/docker-registry.ubuntu + dest: /etc/init.d/docker-registry + mode: "0755" + when: ansible_distribution == "Ubuntu" + + - name: "Install init script" + copy: + src: ../files/docker-registry.gentoo + dest: /etc/init.d/docker-registry + mode: "0755" + when: ansible_distribution == "Gentoo" + + - name: "Enable docker-registry" + service: + name: "{{ item.name }}" + enabled: yes + state: started + runlevel: "{{ item.runlevel }}" + with_items: + - { name: docker-registry, runlevel: default } diff --git a/playbooks/gradle.yaml b/playbooks/gradle.yaml new file mode 100644 index 0000000..4e7dc6a --- /dev/null +++ b/playbooks/gradle.yaml @@ -0,0 +1,53 @@ +--- +- name: "Install gradle" + hosts: target + tasks: + - name: "Add gradle PPA" + apt_repository: + repo: ppa:cwchien/gradle + state: present + when: ansible_distribution == "Ubuntu" + + - name: "Add nodejs PPA" + shell: curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - + when: ansible_distribution == "Ubuntu" + + - name: "Update apt" + apt: + update_cache: yes + when: ansible_distribution == "Ubuntu" + + - name: "Install packages" + apt: + pkg: "{{ item }}" + state: present + with_items: + - gradle + - nodejs + when: ansible_distribution == "Ubuntu" + + - name: "Update yum cache" + yum: + update_cache: yes + when: ansible_distribution == "RedHat" or ansible_distribution == "CentOS" + + - name: "Install packages" + yum: + name: "{{ item }}" + state: present + with_items: + - gradle + - nodejs + when: ansible_distribution == "RedHat" or ansible_distribution == "CentOS" + + - name: "Install packages" + portage: + name: "{{ item }}" + state: present + with_items: + - dev-java/gradle-bin + - net-libs/nodejs + when: ansible_distribution == "Gentoo" + + - name: "Forcibly upgrade npm" + shell: npm install npm@latest -g diff --git a/playbooks/haveged.yaml b/playbooks/haveged.yaml new file mode 100644 index 0000000..11b2371 --- /dev/null +++ b/playbooks/haveged.yaml @@ -0,0 +1,36 @@ +--- +- name: "Install haveged" + hosts: target + tasks: + - name: "Install haveged package" + apt: + pkg: "{{ item }}" + state: present + with_items: + - haveged + when: ansible_distribution == "Ubuntu" + + - name: "Install haveged package" + yum: + name: "{{ item }}" + state: present + with_items: + - haveged + when: ansible_distribution == "RedHat" or ansible_distribution == "CentOS" + + - name: "Install haveged package" + portage: + name: "{{ item }}" + state: present + with_items: + - sys-apps/haveged + when: ansible_distribution == "Gentoo" + + - name: "Enable haveged" + service: + name: "{{ item.name }}" + enabled: yes + state: started + runlevel: "{{ item.runlevel }}" + with_items: + - { name: haveged, runlevel: default } diff --git a/playbooks/install_docker_registry.yaml b/playbooks/install_docker_registry.yaml new file mode 100644 index 0000000..f22e643 --- /dev/null +++ b/playbooks/install_docker_registry.yaml @@ -0,0 +1,4 @@ +--- +- include: docker.yaml +- include: docker_compose.yaml +- include: docker_registry.yaml diff --git a/playbooks/install_openbook.yaml b/playbooks/install_openbook.yaml new file mode 100644 index 0000000..86d4185 --- /dev/null +++ b/playbooks/install_openbook.yaml @@ -0,0 +1,5 @@ +--- +- include: docker.yaml +- include: haveged.yaml +- include: mysql_client.yaml +- include: openbook.yaml diff --git a/playbooks/install_openbook_docker_slave.yaml b/playbooks/install_openbook_docker_slave.yaml new file mode 100644 index 0000000..ebcec43 --- /dev/null +++ b/playbooks/install_openbook_docker_slave.yaml @@ -0,0 +1,9 @@ +--- +- include: salt.yaml +- include: docker.yaml +- include: mysql_client.yaml +- include: openjdk.yaml +- include: gradle.yaml +- include: jenkins_user.yaml +- include: ssh_keys.yaml +- include: ansible.yaml diff --git a/playbooks/jenkins_user.yaml b/playbooks/jenkins_user.yaml new file mode 100644 index 0000000..14085da --- /dev/null +++ b/playbooks/jenkins_user.yaml @@ -0,0 +1,15 @@ +- name: "Create jenkins user" + hosts: all + tasks: + - name: "Create jenkins group" + group: + name: jenkins + state: present + + - name: "Create jenkins user" + user: + name: jenkins + shell: /bin/bash + comment: "jenkins user" + home: /var/lib/jenkins + group: jenkins diff --git a/playbooks/mysql_client.yaml b/playbooks/mysql_client.yaml new file mode 100644 index 0000000..72e0357 --- /dev/null +++ b/playbooks/mysql_client.yaml @@ -0,0 +1,60 @@ +--- +- name: "Install mysql client" + hosts: target + tasks: + - name: "Install mariadb apt key" + shell: apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8 + when: ansible_distribution == "Ubuntu" + + - name: "Configure mariadb.list" + copy: + src: "../files/{{ item }}" + dest: "/etc/apt/sources.list.d/{{ item }}" + mode: 0644 + owner: root + group: root + with_items: + - mariadb.list + when: ansible_distribution == "Ubuntu" + + - name: "Update apt" + apt: + update_cache: yes + when: ansible_distribution == "Ubuntu" + + - name: "Install mariadb-client package" + apt: + pkg: "{{ item }}" + state: present + with_items: + - mariadb-client-10.2 + when: ansible_distribution == "Ubuntu" + + - name: "Add mariadb repository" + yum_repository: + name: MariaDB + description: MariaDB + baseurl: http://yum.mariadb.org/10.2/centos7-amd64 + gpgkey: https://yum.mariadb.org/RPM-GPG-KEY-MariaDB + when: ansible_distribution == "RedHat" or ansible_distribution == "CentOS" + + - name: "Update yum cache" + yum: + update_cache: yes + when: ansible_distribution == "RedHat" or ansible_distribution == "CentOS" + + - name: "Install mariadb-client package" + yum: + name: "{{ item }}" + state: present + with_items: + - MariaDB-client + when: ansible_distribution == "RedHat" or ansible_distribution == "CentOS" + + - name: "Install mariadb-client package" + portage: + name: "{{ item }}" + state: present + with_items: + - dev-db/mariadb + when: ansible_distribution == "Gentoo" diff --git a/playbooks/openbook.yaml b/playbooks/openbook.yaml new file mode 100644 index 0000000..e7609cb --- /dev/null +++ b/playbooks/openbook.yaml @@ -0,0 +1,212 @@ +--- +- name: "Install Openbook" + hosts: target + tasks: + - name: "Install network tools" + apt: + pkg: "{{ item }}" + state: present + with_items: + - netcat-openbsd + - lsof + when: ansible_distribution == "Ubuntu" + + - name: "Install network tools" + yum: + name: "{{ item }}" + state: present + with_items: + - nmap-ncat + - lsof + when: ansible_distribution == "RedHat" or ansible_distribution == "CentOS" + + - name: "Install network tools" + portage: + package: "{{ item }}" + update: yes + changed_use: yes + with_items: + - net-analyzer/netcat + - sys-process/lsof + when: ansible_distribution == "Gentoo" + + - name: "Write hosts entry" + lineinfile: + dest: /etc/hosts + regexp: "{{ item.regexp }}" + line: "{{ item.line }}" + with_items: + - { regexp: '^127\.0\.0\.1.*$', line: "127.0.0.1 localhost {{ ansible_nodename }}" } + + - name: "Create Openbook directories" + file: + path: "{{ item.path }}" + state: directory + mode: "{{ item.mode }}" + with_items: + - { path: /opt/openbook/database, mode: "0755" } + - { path: /opt/openbook/job_scheduler_server, mode: "0755" } + - { path: /opt/openbook/workflow_server, mode: "0755" } + - { path: /opt/openbook/admin_api_server, mode: "0755" } + - { path: /opt/openbook/customer_api_server, mode: "0755" } + - { path: /opt/openbook/admin_web_ui, mode: "0755" } + - { path: /opt/openbook/customer_web_ui, mode: "0755" } + - { path: /etc/openbook/database/conf.d, mode: "0755" } + - { path: /etc/openbook/database/bin, mode: "0755" } + - { path: /var/lib/mysql, mode: "0777" } + - { path: /var/log/mysql, mode: "0777" } + - { path: /etc/openbook/job-scheduler-server, mode: "0777" } + - { path: /etc/openbook/workflow-server, mode: "0777" } + - { path: /etc/openbook/admin-api-server, mode: "0777" } + - { path: /etc/openbook/customer-api-server, mode: "0777" } + - { path: /etc/openbook/admin-web-ui, mode: "0777" } + - { path: /etc/openbook/customer-web-ui, mode: "0777" } + - { path: /var/log/openbook/job-scheduler-server/job-scheduler-server.log, mode: "0777" } + - { path: /var/log/openbook/workflow-server/workflow-server.log, mode: "0777" } + - { path: /var/log/openbook/admin-api-server/admin-api-server.log, mode: "0777" } + - { path: /var/log/openbook/customer-api-server/customer-api-server.log, mode: "0777" } + - { path: /var/log/openbook/admin-web-ui/admin-web-ui.log, mode: "0777" } + - { path: /var/log/openbook/customer-web-ui/customer-web-ui.log, mode: "0777" } + + - name: "Create Openbook files" + template: + src: "../templates/{{ item.src }}" + dest: "{{ item.dest }}" + mode: "{{ item.mode }}" + owner: root + group: root + with_items: + - { src: ci/./openbookctl, dest: /opt/openbook/openbookctl, mode: "0755" } + - { src: database/./run.sh, dest: /opt/openbook/database/run.sh, mode: "0755" } + - { src: job_scheduler_server/./run.sh, dest: /opt/openbook/job_scheduler_server/run.sh, mode: "0755" } + - { src: workflow_server/./run.sh, dest: /opt/openbook/workflow_server/run.sh, mode: "0755" } + - { src: admin_api_server/./run.sh, dest: /opt/openbook/admin_api_server/run.sh, mode: "0755" } + - { src: customer_api_server/./run.sh, dest: /opt/openbook/customer_api_server/run.sh, mode: "0755" } + - { src: admin_web_ui/./run.sh, dest: /opt/openbook/admin_web_ui/run.sh, mode: "0755" } + - { src: customer_web_ui/./run.sh, dest: /opt/openbook/customer_web_ui/run.sh, mode: "0755" } + - { src: job_scheduler_server//etc/openbook/job-scheduler-server/job-scheduler-server.json, dest: /etc/openbook/job-scheduler-server/job-scheduler-server.json, mode: "0644" } + - { src: workflow_server//etc/openbook/workflow-server/workflow-server.json, dest: /etc/openbook/workflow-server/workflow-server.json, mode: "0644" } + - { src: admin_api_server//etc/openbook/admin-api-server/admin-api-server.json, dest: /etc/openbook/admin-api-server/admin-api-server.json, mode: "0644" } + - { src: customer_api_server//etc/openbook/customer-api-server/customer-api-server.json, dest: /etc/openbook/customer-api-server/customer-api-server.json, mode: "0644" } + - { src: admin_web_ui//etc/openbook/admin-web-ui/admin-web-ui.json, dest: /etc/openbook/admin-web-ui/admin-web-ui.json, mode: "0644" } + - { src: customer_web_ui//etc/openbook/customer-web-ui/customer-web-ui.json, dest: /etc/openbook/customer-web-ui/customer-web-ui.json, mode: "0644" } + - { src: database//root/.my.cnf, dest: /root/.my.cnf, mode: "0644" } + - { src: database//etc/openbook/database/create_openbook_schemas.sql, dest: /etc/openbook/database/create_openbook_schemas.sql, mode: "0755" } + - { src: database//etc/openbook/database/debian.cnf, dest: /etc/openbook/database/debian.cnf, mode: "0644" } + - { src: database//etc/openbook/database/conf.d/cluster.cnf, dest: /etc/openbook/database/conf.d/cluster.cnf, mode: "0644" } + - { src: database//etc/openbook/database/conf.d/debconfrc, dest: /etc/openbook/database/conf.d/debconfrc, mode: "0644" } + - { src: database//etc/openbook/database/bin/fix_permissions.sh, dest: /etc/openbook/database/bin/fix_permissions.sh, mode: "0755" } + - { src: database//etc/openbook/database/bin/start_galera_node.sh, dest: /etc/openbook/database/bin/start_galera_node.sh, mode: "0755" } + + - name: "Create Openbook files" + copy: + src: "../files/{{ item.src }}" + dest: "{{ item.dest }}" + mode: "{{ item.mode }}" + owner: root + group: root + with_items: + - { src: ci/./cloudcfg.sh, dest: /opt/openbook/cloudcfg.sh, mode: "0755" } + - { src: database//etc/openbook/database/my.cnf, dest: /etc/openbook/database/my.cnf, mode: "0644" } + + - name: "Create Openbook init script: Ubuntu" + template: + src: "../templates/{{ item.src }}" + dest: "{{ item.dest }}" + mode: "{{ item.mode }}" + owner: root + group: root + with_items: + - { src: ci/./openbook.ubuntu, dest: /etc/init.d/openbook, mode: "0755" } + when: ansible_distribution == "Ubuntu" + + - name: "Create Openbook init script: Redhat" + template: + src: "../templates/{{ item.src }}" + dest: "{{ item.dest }}" + mode: "{{ item.mode }}" + owner: root + group: root + with_items: + - { src: ci/./openbook.redhat, dest: /etc/init.d/openbook, mode: "0755" } + when: ansible_distribution == "RedHat" or ansible_distribution == "CentOS" + + - name: "Create Openbook init script: Gentoo" + template: + src: "../templates/{{ item.src }}" + dest: "{{ item.dest }}" + mode: "{{ item.mode }}" + owner: root + group: root + with_items: + - { src: ci/./openbook.gentoo, dest: /etc/init.d/openbook, mode: "0755" } + when: ansible_distribution == "Gentoo" + + - name: "Add service script to systemd" + shell: systemctl enable openbook + when: ansible_distribution == "Ubuntu" or ansible_distribution == "RedHat" or ansible_distribution == "CentOS" + + - name: "Enable openbook service" + service: + name: "{{ item.name }}" + enabled: yes + runlevel: "{{ item.runlevel }}" + with_items: + - { name: openbook, runlevel: default } + +- name: "Stop Openbook" + hosts: "{{ groups['target']|sort(reverse=True) }}" + serial: 1 + tasks: + - name: "Stop Openbook" + shell: | + /etc/init.d/openbook stop + for cont in $(docker ps | grep -v 'COMMAND' | awk '{print $1}'); do + docker stop ${cont} + done + docker container prune -f + +- name: "Install Openbook" + hosts: target + tasks: + - name: "Delete existing docker images" + shell: | + /opt/openbook/openbookctl stop || true + for i in $(docker images | grep -v CREATED | awk '{print $3}'); do + docker rmi --force $i + done + docker container prune -f + ignore_errors: True + + - name: "Pull docker images" + shell: | + docker login --username "{{ openbook_docker_registry_username }}" --password "{{ openbook_docker_registry_password }}" "{{ openbook_docker_registry_url }}" + if [ "{{ openbook_install_database|string() }}" == "True" ]; then + docker pull "{{ openbook_docker_registry_url }}/openbook_database" + fi + if [ "{{ openbook_install_job_scheduler_server|string() }}" == "True" ]; then + docker pull "{{ openbook_docker_registry_url }}/openbook_job_scheduler_server_unstable" + fi + if [ "{{ openbook_install_workflow_server|string() }}" == "True" ]; then + docker pull "{{ openbook_docker_registry_url }}/openbook_workflow_server_unstable" + fi + if [ "{{ openbook_install_admin_api_server|string() }}" == "True" ]; then + docker pull "{{ openbook_docker_registry_url }}/openbook_admin_api_server_unstable" + fi + if [ "{{ openbook_install_customer_api_server|string() }}" == "True" ]; then + docker pull "{{ openbook_docker_registry_url }}/openbook_customer_api_server_unstable" + fi + if [ "{{ openbook_install_admin_web_ui|string() }}" == "True" ]; then + docker pull "{{ openbook_docker_registry_url }}/openbook_admin_web_ui_unstable" + fi + if [ "{{ openbook_install_customer_web_ui|string() }}" == "True" ]; then + docker pull "{{ openbook_docker_registry_url }}/openbook_customer_web_ui_unstable" + fi + +- name: "Start Openbook" + hosts: "{{ groups['target']|sort }}" + serial: 1 + tasks: + - name: "Start Openbook" + shell: /etc/init.d/openbook start + when: openbook_start_app == True diff --git a/playbooks/openjdk.yaml b/playbooks/openjdk.yaml new file mode 100644 index 0000000..00c7d90 --- /dev/null +++ b/playbooks/openjdk.yaml @@ -0,0 +1,59 @@ +--- +- name: "Install openjdk" + hosts: target + tasks: + - name: "Update apt" + apt: + update_cache: yes + when: ansible_distribution == "Ubuntu" + + - name: "Install openjdk package" + apt: + pkg: "{{ item }}" + state: present + with_items: + - openjdk-8-jdk-headless + when: ansible_distribution == "Ubuntu" + + - name: "Update yum cache" + yum: + update_cache: yes + when: ansible_distribution == "RedHat" or ansible_distribution == "CentOS" + + - name: "Install openjdk package" + yum: + name: "{{ item }}" + state: present + with_items: + - openjdk + when: ansible_distribution == "RedHat" or ansible_distribution == "CentOS" + + - name: "Install icedtea package" + portage: + name: "{{ item }}" + state: present + with_items: + - dev-java/icedtea:8 + when: ansible_distribution == "Gentoo" + + - name: "Set icedtea-8 as default java" + shell: java-config -S icedtea-8 + when: ansible_distribution == "Gentoo" + + - name: "/dev/urandom fix" + lineinfile: + dest: "/etc/java-8-openjdk/security/java.security" + regexp: "{{ item.regexp }}" + line: "{{ item.line }}" + with_items: + - { regexp: '^securerandom.source=file:/dev/random.*$', line: "securerandom.source=file:/dev/urandom" } + when: ansible_distribution == "Ubuntu" + + - name: "/dev/urandom fix" + lineinfile: + dest: "/etc/java-config-2/current-system-vm/jre/lib/security/java.security" + regexp: "{{ item.regexp }}" + line: "{{ item.line }}" + with_items: + - { regexp: '^securerandom.source=file:/dev/random.*$', line: "securerandom.source=file:/dev/urandom" } + when: ansible_distribution == "Gentoo" diff --git a/playbooks/salt.yaml b/playbooks/salt.yaml new file mode 100644 index 0000000..bdf6b7e --- /dev/null +++ b/playbooks/salt.yaml @@ -0,0 +1,96 @@ +--- +- name: "Install salt" + hosts: all + tasks: + - name: "Create salt-master directories" + file: + path: "{{ item }}" + state: directory + mode: 0755 + owner: root + group: root + with_items: + - /srv + - /srv/keys + - /srv/reactor + + - name: "Create salt-master symlinks" + file: + src: "/var/lib/jenkins/workspace/build-docker-container/{{ item }}" + dest: "/srv/{{ item }}" + state: link + force: yes + with_items: + - bootstrap + - pillar + - salt + + - name: "Install salt apt key" + shell: curl -fsSL https://repo.saltstack.com/apt/ubuntu/16.04/amd64/latest/SALTSTACK-GPG-KEY.pub | apt-key add - + when: ansible_distribution == "Ubuntu" + + - name: "Configure saltstack.list" + copy: + src: "../files/{{ item }}" + dest: "/etc/apt/sources.list.d/{{ item }}" + mode: 0644 + owner: root + group: root + with_items: + - saltstack.list + when: ansible_distribution == "Ubuntu" + + - name: "Update apt" + apt: + update_cache: yes + when: ansible_distribution == "Ubuntu" + + - name: "Install salt packages" + apt: + pkg: "{{ item }}" + state: present + with_items: + - jq + - ruby + - salt-master + - salt-minion + when: ansible_distribution == "Ubuntu" + + - name: "Install salt packages" + portage: + package: "{{ item }}" + update: yes + changed_use: yes + with_items: + - app-misc/jq + - dev-lang/ruby + - app-admin/salt + when: ansible_distribution == "Gentoo" + + - name: "Configure salt-master" + copy: + src: "../files/{{ item }}" + dest: "/etc/salt/{{ item }}" + mode: 0644 + owner: root + group: root + with_items: + - master + + - name: "Configure salt-minion" + lineinfile: + dest: "/etc/salt/minion" + regexp: "{{ item.regexp }}" + line: "{{ item.line }}" + with_items: + - { regexp: '^#master:.*$', line: "master: {{ salt_master }}" } + + - name: "Enable salt services" + service: + name: "{{ item.name }}" + enabled: yes + state: started + runlevel: "{{ item.runlevel }}" + with_items: + - { name: salt-master, runlevel: default } + - { name: salt-minion, runlevel: default } diff --git a/playbooks/ssh_keys.yaml b/playbooks/ssh_keys.yaml new file mode 100644 index 0000000..e0046b2 --- /dev/null +++ b/playbooks/ssh_keys.yaml @@ -0,0 +1,39 @@ +--- +- name: "Generate SSH keypair" + hosts: all + vars: + ssh_privkey_path: /root/.ssh/id_rsa + tasks: + - name: "Detect existing SSH privkey" + stat: + path: "{{ ssh_privkey_path }}" + register: ssh_privkey + + - name: "Detect existing SSH pubkey" + stat: + path: "{{ ssh_privkey_path }}.pub" + register: ssh_pubkey + + - name: "Generate SSH keypair" + shell: ssh-keygen -q -t rsa -b 4096 -f "{{ ssh_privkey_path }}" -N '' + when: ssh_privkey.stat.exists == False or ssh_pubkey.stat.exists == False + +- name: "Generate SSH keypair" + hosts: all + become_user: jenkins + vars: + ssh_privkey_path: /var/lib/jenkins/.ssh/id_rsa + tasks: + - name: "Detect existing SSH privkey" + stat: + path: "{{ ssh_privkey_path }}" + register: ssh_privkey + + - name: "Detect existing SSH pubkey" + stat: + path: "{{ ssh_privkey_path }}.pub" + register: ssh_pubkey + + - name: "Generate SSH keypair" + shell: ssh-keygen -q -t rsa -b 4096 -f "{{ ssh_privkey_path }}" -N '' + when: ssh_privkey.stat.exists == False or ssh_pubkey.stat.exists == False diff --git a/playbooks/stop_start_openbook.yaml b/playbooks/stop_start_openbook.yaml new file mode 100644 index 0000000..83c1d57 --- /dev/null +++ b/playbooks/stop_start_openbook.yaml @@ -0,0 +1,28 @@ +--- +- name: "Verify action to take" + hosts: localhost + tasks: + - name: "Check that -e 'action=[stop|start]' was passed in" + fail: msg="The variable 'action' was not passed in with a value of 'stop' or 'start' on the command line." + when: action not in ["stop", "start"] + +- name: "Stop Openbook" + hosts: "{{ groups['target']|sort(reverse=True) }}" + serial: 1 + tasks: + - name: "Stop Openbook" + shell: | + /etc/init.d/openbook stop + for cont in $(docker ps | grep -v 'COMMAND' | awk '{print $1}'); do + docker stop ${cont} + done + docker container prune -f + when: action == "stop" + +- name: "Start Openbook" + hosts: "{{ groups['target']|sort }}" + serial: 1 + tasks: + - name: "Start Openbook" + shell: /etc/init.d/openbook start + when: action == "start" |
