In this lab, you will utilize Ansible to set up a Continuous Deployment (CD) process for your application.
6 Points:
-
Create an Ansible Role:
- Develop an Ansible role specifically for deploying your application's Docker image, it can be done manually or via
ansible-galaxy init roles/web_app. Call itweb_app. - Define variables in
roles/web_app/defaults/main.yml. - Add tasks to
roles/web_app/tasks/main.ymlto pull the Docker image and start the container.
Managing just a container is bad practice, you can omit it and move to the Task 2 directly.
- Develop an Ansible role specifically for deploying your application's Docker image, it can be done manually or via
-
Update the Playbook:
- Modify your Ansible playbook to integrate the new role you've created for Docker image deployment.
-
Deployment Output:
- Execute your playbook to deploy the role.
- Provide the last 50 lines of the output from your deployment command in the
ANSIBLE.mdfile.
4 Points:
-
Group Tasks with Blocks:
- Organize related tasks within your playbooks using Ansible blocks.
- Implement logical blocks. For example:
- name: Setup Docker Environment block: - name: Install Docker apt: name: docker.io state: present - name: Start Docker Service service: name: docker state: started enabled: yes tags: - setup
-
Role Dependency:
- Set the role dependency for your
web_approle to include thedockerrole. - Specify dependencies in
roles/web_app/meta/main.yml.
- Set the role dependency for your
-
Apply Tags:
-
Implement Ansible tags to group tasks logically and enable selective execution. For example:
- name: Pull Docker image docker_image: name: "{{ docker_image }}" source: pull tags: - docker
-
Run specific tags. For example:
ansible-playbook site.yml --tags docker
-
-
Wipe Logic:
- Create a wipe logic in
roles/web_app/tasks/0-wipe.yml. This should include removing your Docker container and all related files. - Ensure that this wipe process can be enabled or disabled by using a variable, for example,
web_app_full_wipe=true.
- Create a wipe logic in
-
Separate Tag for Wipe:
- Utilize a distinct tag for the Wipe section of your Ansible playbook. This allows you to run the wipe tasks independently from the main tasks.
-
Docker Compose File:
-
Write a Jinja2 template (
roles/web_app/templates/docker-compose.yml.j2). For example:version: '3' services: app: image: "{{ docker_image }}" ports: - "{{ app_port }}:80"
-
Deliver the template using the
templatemodule inroles/web_app/tasks/main.yml. -
Suggested structure:
. |-- defaults | `-- main.yml |-- meta | `-- main.yml |-- tasks | |-- 0-wipe.yml | `-- main.yml `-- templates `-- docker-compose.yml.j2
-
-
Create
README.md:- Create a
README.mdfile in theansible/roles/web_appfolder. - Use a suggested Docker Markdown template from the previous lab to describe your role, its requirements and usage.
- Create a
2.5 Points:
-
Create an Extra Playbook:
- Develop an additional Ansible playbook specifically for your bonus application.
- You can reuse the existing Ansible role you created for your primary application or create a new one.
- Suggested structure:
. `--ansible `-- playbooks `-- dev |-- app_python | `-- main.yaml `-- app_go `-- main.yaml
- Use proper Markdown formatting and structure for documentation files.
- Organize files within the lab folder with suitable naming conventions.
- Create pull requests (PRs) as needed: from your fork to the main branch of this repository, and from your fork's branch to your fork's master branch.
- Follow the suggested structure for your Ansible roles, tasks, and templates.
- Utilize Ansible best practices such as grouping tasks with blocks, applying tags, and separating roles logically.
Note: Apply diligence to your Ansible implementation, follow best practices, and clearly document your work to achieve the best results in this lab assignment.