Add ansible configuration for master host 04/74304/13
authorAdam Malinowski <a.malinowsk2@partner.samsung.com>
Mon, 13 Jun 2016 14:51:53 +0000 (16:51 +0200)
committerAdam Malinowski <a.malinowsk2@partner.samsung.com>
Thu, 17 Nov 2016 10:33:09 +0000 (11:33 +0100)
Change-Id: If0cbcb3a79689076fd00319935b03fa643bc08d3

config/hosts/README
config/hosts/do_config.sh [new file with mode: 0755]
config/hosts/hosts.sample
config/hosts/master/do_master.sh [new file with mode: 0755]
config/hosts/master/master.yml [new file with mode: 0644]
config/hosts/master/roles/system/tasks/main.yml [new file with mode: 0644]
config/hosts/master/roles/testlab/tasks/main.yml [new file with mode: 0644]
config/hosts/master/roles/user/tasks/main.yml [new file with mode: 0644]

index a306ba2..e9d3bc5 100644 (file)
@@ -25,3 +25,6 @@ Note that runner and master may be the same machine.
 Next step is to install ssh key in order to be able to run other scripts.
 To do that run script named 'installkey.sh'. It will execute ansible playbook
 'installsshkey.yml' and you will have to enter password for specified user.
+
+Now you can run script 'do_config.sh' which will execute ansible with playbook
+for 'master' machine.
diff --git a/config/hosts/do_config.sh b/config/hosts/do_config.sh
new file mode 100755 (executable)
index 0000000..6d14ba6
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/sh
+cd master
+./do_master.sh
+
+cd ..
index 9f71eec..a25eb17 100644 (file)
@@ -14,3 +14,4 @@
 
 [all:vars]
 ansible_user=vagrant
+proxy=http://106.116.37.23:3128
diff --git a/config/hosts/master/do_master.sh b/config/hosts/master/do_master.sh
new file mode 100755 (executable)
index 0000000..efe77f2
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+ansible-playbook master.yml --inventory-file=../hosts
diff --git a/config/hosts/master/master.yml b/config/hosts/master/master.yml
new file mode 100644 (file)
index 0000000..7d13d58
--- /dev/null
@@ -0,0 +1,13 @@
+---
+# This playbook configures master machine
+
+- hosts: master
+  become: yes
+  become_method: sudo
+  vars:
+    username: pita # Prerelease Image Testing Automation
+
+  roles:
+    - user
+    - system
+    - testlab
diff --git a/config/hosts/master/roles/system/tasks/main.yml b/config/hosts/master/roles/system/tasks/main.yml
new file mode 100644 (file)
index 0000000..92cb500
--- /dev/null
@@ -0,0 +1,34 @@
+---
+# This role configures system and installs
+
+- name: Update packages info
+  apt:
+    update_cache: yes
+    force: yes
+
+- name: Upgrade packages
+  apt:
+    upgrade: full
+    force: yes
+
+- name: Install tools
+  apt: "name={{ item }} state=present force=yes"
+  with_items:
+    - wget
+    - task-spooler
+    - python-bs4
+    - git
+
+- name: Set http_proxy environment variable
+  lineinfile:
+    dest: /etc/environment
+    state: present
+    regexp: '^http_proxy'
+    line: 'http_proxy="{{ proxy }}"'
+
+- name: Set HTTP_PROXY environment variable
+  lineinfile:
+    dest: /etc/environment
+    state: present
+    regexp: '^HTTP_PROXY'
+    line: 'HTTP_PROXY="{{ proxy }}"'
diff --git a/config/hosts/master/roles/testlab/tasks/main.yml b/config/hosts/master/roles/testlab/tasks/main.yml
new file mode 100644 (file)
index 0000000..b1ce839
--- /dev/null
@@ -0,0 +1,16 @@
+---
+# This role does the job related to testlab-major
+
+- name: Prepare testlab-major directory
+  file:
+    path: /opt/testlab-major
+    state: directory
+    owner: "{{ username }}"
+    group: "{{ username }}"
+
+- name: Clone testlab-major repo
+  become: yes
+  become_user: "{{ username }}"
+  git:
+    repo: git://git.tizen.org/tools/testlab/major
+    dest: /opt/testlab-major
diff --git a/config/hosts/master/roles/user/tasks/main.yml b/config/hosts/master/roles/user/tasks/main.yml
new file mode 100644 (file)
index 0000000..705258e
--- /dev/null
@@ -0,0 +1,36 @@
+---
+# This playbook creates and sets up user
+
+- name: "Add group {{ username }}"
+  group:
+    name: "{{ username }}"
+
+# Add user
+- name: "Add user {{ username }}"
+  user:
+    name: "{{ username }}"
+    groups: "{{ username }},sudo"
+    home: /home/{{ username }}
+
+- name: Remove ssh key from user
+  become: yes
+  become_user: "{{ username }}"
+  file:
+    path: "{{ item }}"
+    state: absent
+  with_items:
+    - "~/.ssh/id_rsa"
+    - "~/.ssh/id_rsa.pub"
+
+- name: Generate ssh key for user
+  become: yes
+  become_user: "{{ username }}"
+  command: "ssh-keygen -f ~/.ssh/id_rsa -N ''"
+
+- name: Fetch generated ssh key
+  become: yes
+  become_user: "{{ username }}"
+  fetch:
+    src: ~/.ssh/id_rsa.pub
+    dest: ~/tmp/id_rsa.pub
+    flat: yes