Skip to content
Snippets Groups Projects
Commit 8148d5d1 authored by fejao's avatar fejao
Browse files

Merge branch 'Adding_role_clone_repositories' into 'main'

Adding role clone repositories

See merge request !3
parents a6e955f0 194b72d0
No related branches found
No related tags found
1 merge request!3Adding role clone repositories
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
## WIP ## WIP
- [ ] finish the roles for deploying the **c3InfoDesk Printer** - [ ] finish the roles for deploying the **c3InfoDesk Printer**
- [x] dependencies - [x] dependencies
- [ ] clone_repositories - [x] clone_repositories
- [ ] docker_images - [ ] docker_images
- [ ] docker_containers - [ ] docker_containers
- [ ] set ansible-lint - [ ] set ansible-lint
...@@ -21,6 +21,7 @@ This is a repo for deploying the the printer system used at the c3infodesk for p ...@@ -21,6 +21,7 @@ This is a repo for deploying the the printer system used at the c3infodesk for p
Here are the used roles: Here are the used roles:
- [dependencies](roles/dependencies/README.md) - [dependencies](roles/dependencies/README.md)
- [clone_repositories](roles/clone_repositories/README.md)
## License ## License
......
...@@ -223,6 +223,8 @@ inventory=$PWD/inventories/hosts ...@@ -223,6 +223,8 @@ inventory=$PWD/inventories/hosts
# (string) Sets the login user for the target machines # (string) Sets the login user for the target machines
# When blank it uses the connection plugin's default, normally the user currently executing Ansible. # When blank it uses the connection plugin's default, normally the user currently executing Ansible.
;remote_user= ;remote_user=
###
remote_user=test-user
# (pathspec) Colon-separated paths in which Ansible will search for Roles. # (pathspec) Colon-separated paths in which Ansible will search for Roles.
;roles_path=/home/fejao/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles ;roles_path=/home/fejao/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles
......
--- ---
# group_vars from test_servers # group_vars from test_servers
###
### roles/test
###
var_setted_everywhere: 'ANSWER EVERYWHERE FROM /inventories/group_vars/example_test_servers.yaml' var_setted_everywhere: 'ANSWER EVERYWHERE FROM /inventories/group_vars/example_test_servers.yaml'
var_setted_only_group_vars: "MESSAGE FROM GROUP_VARS ONLY" var_setted_only_group_vars: "MESSAGE FROM GROUP_VARS ONLY"
###
### roles/clone_repositories
###
c3infodesk_printer_folder: "Coding/c3infodesk-printer"
...@@ -14,3 +14,9 @@ var_setted_only_host_vars: "MESSAGE FROM HOST_VARS ONLY" ...@@ -14,3 +14,9 @@ var_setted_only_host_vars: "MESSAGE FROM HOST_VARS ONLY"
### roles/dependencies -> !!! One of the users should be at least the one setted at ansible.cfg ### roles/dependencies -> !!! One of the users should be at least the one setted at ansible.cfg
### ###
docker_users: [test-user] docker_users: [test-user]
###
### roles/clone_repositories
###
# c3infodesk_printer_repo_clone: true
c3infodesk_printer_repo_new_branch_name: "test_branch"
---
# Runs example for
- hosts:
- example_servers_group
roles:
# - dependencies
- clone_repositories
# clone-repositories
This ansible-role for dealing with cloning the repositories necessary for deploying the system used from **c3infodesk**.
## Requirements
- To have [ansible](https://docs.ansible.com/ansible/latest/installation_guide/installation_distros.html) installed at your system.
- Set your **remote_user** configuration at the **ansible.cfg** file.
- Set your **inventories/host_vars/<TARGET_NAME>** file.
## Role Variables
Here are the variables setted:
- ### From: inventories/host_vars/<TARGET_NAME>
Here are the variables that you should be changing for your own deployment.
- **c3infodesk_printer_repo_new_branch_name**: DEFAULT="test_branch"
- The branch name that it will be checked-out for avoiding updating the **main** branch
- ### From: inventories/group_vars/<TARGET_GROUP>
- **c3infodesk_printer_folder**: DEFAULT="Coding/c3infodesk-printer"
- The folder where to clone the repositories
- ### From: roles/clone-repositories/defaults/main.yml
- **c3infodesk_printer_repo_clone**: DEFAULT=true
- If it should or not clone the repository.
- **c3infodesk_printer_repo_url**: DEFAULT="https://git.cccv.de/fejao/c3infodesk-printer.git"
- The repository to be cloned.
- **c3infodesk_printer_repo_new_branch_name**: DEFAULT="new_branch_name"
- The branch name to be set after cloning the repository.
## Dependencies
The role dependencies are:
- [dependencies(role)](roles/dependencies/README.md)
## Example Playbook
- ### Using the provided example
For using the playbook **playbook_example_03_clone_repositories.yml** file you only nned to:
- Change the user at the **ansible.cfg** file at the field **remote_user** for acessing your target.
- Update the file **inventories/host_vars/example_server.yml** and change the value for **ansible_become_pass** from the **remote_user**
- Update the **inventories/hosts** file and change the **example_server** with the IP address from your target.
And run the command:
```bash
ansible-playbook -i inventories/hosts playbook_example_03_clone_repositories.yml
```
- ### Setting your own example
After setting your variables at **inventories/host_vars/<HOST_NAME>**, you can add this role to your playbook as a regular role.
Here is an example using the **<HOST_NAME>** as **test_servers**
```yaml
- hosts:
- test_servers
roles:
- clone_repositories
```
And call the playbook as:
```bash
ansible-playbook -i <INVENTORY> <PLAYBOOK_NAME>.yml
```
## License
MIT / BSD
## Author Information
![fejao logo](../../files/from_authors/fejao_logo_circle.png "fejao") [https://chaos.social/@fejao](https://chaos.social/@fejao)
---
# defaults file for clone-repository
###
### SET ON inventories/group_vars !!! DON'T CHANGE THIS HERE !!!
###
# c3infodesk_printer_folder
###
### LOCAL
###
c3infodesk_printer_repo_clone: true
c3infodesk_printer_repo_url: "https://git.cccv.de/fejao/c3infodesk-printer.git"
c3infodesk_printer_repo_new_branch_name: "new_branch_name"
galaxy_info:
author: your name
description: your role description
company: your company (optional)
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)
min_ansible_version: 2.1
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
# dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
dependencies:
- role: dependencies
---
# tasks file for clone-repository
- name: Clone the printer repository
ansible.builtin.import_tasks: printer.yml
when: c3infodesk_printer_repo_clone | bool
# - name: Clone the questions repository
# ansible.builtin.import_tasks: questions.yml
# when: repo_c3infodesk_clone_questions | bool
---
# tasks file for clone-repository from c3infodesk printer
- name: PRINTER | Checking if the repository already exists
ansible.builtin.git:
repo: "{{ c3infodesk_printer_repo_url }}"
dest: "{{ c3infodesk_printer_folder }}"
clone: no
update: no
register: check_repository
- name: PRINTER | Check repository exists answer
ansible.builtin.debug:
msg: "Repository already exists on target"
when: not check_repository.changed
- name: PRINTER | Clone the printer repository
ansible.builtin.git:
repo: "{{ c3infodesk_printer_repo_url }}"
dest: "{{ c3infodesk_printer_folder }}"
depth: 1
when:
- check_repository.before is defined
- check_repository.before == None
- name: PRINTER | Creates and changes to new branch on cloned repository
ansible.builtin.command:
cmd: "git checkout -b '{{ c3infodesk_printer_repo_new_branch_name }}'"
args:
chdir: "{{ c3infodesk_printer_folder }}"
when:
- check_repository.before is defined
- check_repository.before == None
...@@ -9,13 +9,15 @@ This role uses great part of it from [geerlingguy](https://github.com/geerlinggu ...@@ -9,13 +9,15 @@ This role uses great part of it from [geerlingguy](https://github.com/geerlinggu
The original code used can be found at: [https://github.com/geerlingguy/ansible-role-docker](https://github.com/geerlingguy/ansible-role-docker) The original code used can be found at: [https://github.com/geerlingguy/ansible-role-docker](https://github.com/geerlingguy/ansible-role-docker)
## Requirements ## Requirements
To have [ansible](https://docs.ansible.com/ansible/latest/installation_guide/installation_distros.html) installed at your system. - To have [ansible](https://docs.ansible.com/ansible/latest/installation_guide/installation_distros.html) installed at your system.
- Set your **remote_user** configuration at the **ansible.cfg** file.
- Set your **inventories/host_vars/<TARGET_NAME>** file.
## Role Variables ## Role Variables
Here are the variables setted: Here are the variables setted:
### From: inventories/host_vars/<TARGET_NAME> - ### From: inventories/host_vars/<TARGET_NAME>
Here are the variables that you should be changing for your own deployment Here are the variables that you should be changing for your own deployment.
- **docker_users**: DEFAULT="test-user" - **docker_users**: DEFAULT="test-user"
- The users to be added to the docker group. - The users to be added to the docker group.
- These users should should contain at least the same user setted on **ansible.cfg** at the **remote_user** - These users should should contain at least the same user setted on **ansible.cfg** at the **remote_user**
...@@ -23,10 +25,10 @@ Here are the variables that you should be changing for your own deployment ...@@ -23,10 +25,10 @@ Here are the variables that you should be changing for your own deployment
- The password used from the user setted on **ansible.cfg** at the **remote_user** - The password used from the user setted on **ansible.cfg** at the **remote_user**
### From: inventories/group_vars/<TARGET_GROUP> - ### From: inventories/group_vars/<TARGET_GROUP>
This role needs no variable setted on **group_vars** This role needs no variable setted on **group_vars**
### From: roles/clone-repositories/defaults/main.yml - ### From: roles/clone-repositories/defaults/main.yml
Here are the variables used for this role. Please don't change then here but instead in **inventories/host_vars/<TARGET_NAME>** Here are the variables used for this role. Please don't change then here but instead in **inventories/host_vars/<TARGET_NAME>**
- **docker_users** - **docker_users**
...@@ -64,16 +66,18 @@ Here are the variables used for this role. Please don't change then here but ins ...@@ -64,16 +66,18 @@ Here are the variables used for this role. Please don't change then here but ins
- **docker_yum_gpg_key** - **docker_yum_gpg_key**
- **docker_daemon_options** - **docker_daemon_options**
### From: roles/dependencies/vars/main.yml - ### From: roles/dependencies/vars/main.yml
- **docker_packages** - **docker_packages**
- **docker_compose_package** - **docker_compose_package**
## Dependencies ## Dependencies
This role have no dependency from any another role. This role have no dependency from any another role.
# Example Playbook
### Using the provided example ## Example Playbook
- ### Using the provided example
For using the playbook **playbook_example_02_dependencies.yml** file you only nned to: For using the playbook **playbook_example_02_dependencies.yml** file you only nned to:
- Change the user at the **ansible.cfg** file at the field **remote_user** for acessing your target. - Change the user at the **ansible.cfg** file at the field **remote_user** for acessing your target.
- Update the file **inventories/host_vars/example_server.yml** and change the value for **ansible_become_pass** from the **remote_user** - Update the file **inventories/host_vars/example_server.yml** and change the value for **ansible_become_pass** from the **remote_user**
...@@ -84,7 +88,7 @@ And run the command: ...@@ -84,7 +88,7 @@ And run the command:
ansible-playbook -i inventories/hosts playbook_example_02_dependencies.yml ansible-playbook -i inventories/hosts playbook_example_02_dependencies.yml
``` ```
### Setting your own example - ### Setting your own example
After setting your variables at **inventories/host_vars/<HOST_NAME>**, you can add this role to your playbook as a regular role. After setting your variables at **inventories/host_vars/<HOST_NAME>**, you can add this role to your playbook as a regular role.
Here is an example using the **<HOST_NAME>** as **test_servers** Here is an example using the **<HOST_NAME>** as **test_servers**
...@@ -102,10 +106,12 @@ And call the playbook as: ...@@ -102,10 +106,12 @@ And call the playbook as:
ansible-playbook -i <INVENTORY> <PLAYBOOK_NAME>.yml ansible-playbook -i <INVENTORY> <PLAYBOOK_NAME>.yml
``` ```
## License ## License
MIT / BSD MIT / BSD
## Author Information ## Author Information
![fejao logo](../../files/from_authors/fejao_logo_circle.png "fejao") [https://chaos.social/@fejao](https://chaos.social/@fejao) ![fejao logo](../../files/from_authors/fejao_logo_circle.png "fejao") [https://chaos.social/@fejao](https://chaos.social/@fejao)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment