donal
2018-04-06 da55a5897355eb4184312e47127a779e6b83d7ec
commit | author | age
74d1f1 1 # The Manual Menace
0f4d08 2
74d1f1 3 > In this lab learners will use Ansible to drive automated provisioning of Projects, Access Control, Git, Jenkins and Nexus
D 4
5 _____
0f4d08 6
D 7 ## Learning Outcomes
8 As a learner you will be able to
74d1f1 9
D 10 1. Run the OpenShift Applier to automate creating cluster content
11 1. Create and admin project namespaces in OpenShift
12 1. Deploy commonly used applications to support the development process
0f4d08 13
D 14 ## Tools and Frameworks
15
74d1f1 16 * [GitLab](https://about.gitlab.com/) - Community driven Git server now with integrated DevOps Toolchain.
D 17 * [Nexus](https://www.sonatype.com/nexus-repository-sonatype) - Repository manager for storing lots of application types. Can also host `npm` and `Docker` registries.
18 * [Jenkins](https://jenkins.io/) - OpenSource Build automation server. Highly customisable with plugins.
19 * [Ansible](https://www.ansible.com/) - IT Automation tool used to provision and manage state of cloud and physical infrastructure.
20 * [OpenShift Applier](https://github.com/redhat-cop/openshift-applier) - Community driven Git server
0f4d08 21
74d1f1 22 ## Big Picture
D 23 This exercise begins with an empty Cluster
24 > TODO - add big picture here...
25
26 _____
0f4d08 27
D 28 ## 10,000 Ft View
74d1f1 29 > This lab is aimed at the creation of the tooling that will be used to support the rest of the Exercises. The highlevel goal is to create a collection of project namespaces and populate them with Git, Jenkins & Nexus.
D 30
31 If you're feeling confident and don't want to follow the step-by-step guide these highlevel instructions should provide a challenge for you:
32
33 2. Clone the repo `git@github.com:rht-labs/enablement-ci-cd.git` which contains the scaffold of the project.
34 2. Create `<your-name>-ci-cd`, `<your-name>-dev` and `<your-name>-test` project namespaces using the inventory and run them with the OpenShift Applier to populate the cluster
35 2. Use the templates provided to create build and deployment configs in `<your-name>-ci-cd` for:
36     * Nexus
37     * GitLab
38     * Jenkins
39 2. Commit your `enablement-ci-cd` repository to the GitLab Instance you've created
0f4d08 40
D 41 ## Step by Step Instructions
bd7806 42 > This is a structured guide with references to exact filenames and explanations.
0f4d08 43
bd7806 44 ### Part 1 - Create OpenShift Projects
D 45 3. Clone the scaffold project to your local machine and open it in your favourite editor.
46 ```bash
47 git clone git@github.com:rht-labs/enablement-ci-cd.git
0f4d08 48 ```
D 49
bd7806 50 3. The project is laid out as follows
D 51 ```
52 .
53 ├── README.md
54 ├── docker
55 │   └── jenkins-slave-node
56 ├── inventory
57 │   ├── group_vars
58 │   │   └── all.yml
59 │   └── hosts
60 ├── jenkins-s2i
61 │   ├── configuration
62 ├── params
63 │   └── project-requests-ci-cd
64 ├── requirements.yml
65 └── templates
66         └── project-requests.yml
67 ```
68  * `docker` folder contains our jenkins-slave images that will be used by the builds.
69  * `jenkins-s2i` contains the configuration and plugins we want to bring jenkins to life with
70  * `params` houses the variables we will load the templates with
71  * `templates` is a collection of OpenShift templates
72  * `inventory/group_vars/all.yml` is the collection of objects we want to insert into the cluster.
73  * `requirements.yml` is a manifest which contains the ansible modules needed to run the playbook
74 Open the `inventory/group_vars/all.yml` file; you should see a some variables setup to create the `ci-cd` namespace. This calls the `templates/project-requests.yml` template with the `params/project-requests-ci-cd` parameters. We will add some additional content here but first let's explore the parameters and the template
75
76 3. Open the `params/project-requests-ci-cd` and replace the `<your name or initials>` with your name to create the correstponding projects in the cluster. 
77 ![new-item](../images/ci-cd-project-namespace.png)
78
79 3. Create another two params files for `params/project-requests-dev` & `params/project-requests-test` and add the `NAMESPACE=<your name>-dev` && `NAMESPACE=<your name>-test` and update their Display names.
80
81 3. In the `inventory/group_vars/all.yml` file; add the new inventory items for the projects you want to create (dev & test) by adding another object to the content array. You can copy and paste them from the `ci-cd` example and update them accordingly eg
82 ```yaml
83   - name: <your name>-dev
84     template: "{{ inventory_dir }}/../templates/project-requests.yml"
85     template_action: create
86     params: "{{ inventory_dir }}/../params/project-requests-dev"
87     tags:
88     - projects
89   - name: <your name>-test
90     template: "{{ inventory_dir }}/../templates/project-requests.yml"
91     template_action: create
92     params: "{{ inventory_dir }}/../params/project-requests-test"
93     tags:
94     - projects
95 ```
da55a5 96 ![project-request-yaml](../images/project-request-yml.png)
bd7806 97
D 98 3. With the configuration in place; install the OpenShift Applier dependency
99 ```bash
100 $ ansible-galaxy install -r requirements.yml --roles-path=roles
101 ```
102
103 3. Apply the inventory by logging into OpenShift and then running 
104 ```bash
105 $ oc login -p <password> -u <user> <cluster_url>
106 $ ansible-playbook roles/casl-ansible/playbooks/openshift-cluster-seed.yml -i inventory/
107 ``` 
108
109 3. Once successful you should see an output similar to this ![playbook-success](../images/play-book-success.png)
110
111 ### Part 2 - Nexus and GitLab
da55a5 112 > _Now that we have our Projects setup; we can start to populate them with Apps to be used in our dev lifecycle_
bd7806 113
da55a5 114 4. In the `enablement-ci-cd` repo, checkout the templates for GitLab and Nexus by running
D 115 ```bash
116 $ git checkout 
117 ```
118
119 4. 
120 4. 
121 4. 
122 4. 
bd7806 123
D 124 ### Part 3 - Jenkins & s2i
125 5. Add new plugin ...
126
127 ### Part 4 - live, die repeat
128 6. Commit your code to the new repo in GitLab
129
130 6. Burn it to the ground 
0f4d08 131
74d1f1 132 _____
D 133
0f4d08 134 ## Extension Tasks
D 135 > Ideas for go-getters. Advanced topic for doers to get on with if they finish early. These will usually not have a solution and are provided for additional scope.
136
137  - Add Auth to your application
138  - Do some other stuff
139
74d1f1 140 _____
D 141
0f4d08 142 ## Additional Reading
D 143  > List of links or other reading that might be of use / reference for the exercise