diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a2be19e928bc8513b416391d4ed348462cc85740..850aaaff7740b1397e7542f6d37b0dbf58a9a983 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,6 +11,7 @@ variables: PLAYBOOK_PATH_FOR_ROLE_CLONE_REPOSITORIES: "ci-cd/03_clone_repositories.yml" PLAYBOOK_PATH_FOR_ROLE_DOCKER_IMAGES: "ci-cd/04_docker_images.yml" PLAYBOOK_PATH_FOR_ROLE_DOCKER_CONTAINERS: "ci-cd/05_docker_containers.yml" + PLAYBOOK_PATH_FOR_ROLE_OH_MY_BASH: "ci-cd/06_oh_my_bash.yml" stages: - syntax-check @@ -75,6 +76,17 @@ syntax-docker-containers: - ansible-playbook --syntax-check -i $INVENTORIES_PATH $PLAYBOOK_PATH_FOR_ROLE_DOCKER_CONTAINERS allow_failure: false +syntax-oh-my-bash: + stage: syntax-check + image: python:3.10.15-bullseye + before_script: + - apt-get update && apt-get install -y python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/* + - pip3 install -r ci-cd/requirements.txt + script: + - echo "Running ansible-playbook --syntax-check tests at the role-> 'docker_containers'" + - ansible-playbook --syntax-check -i $INVENTORIES_PATH $PLAYBOOK_PATH_FOR_ROLE_OH_MY_BASH + allow_failure: false + ### ### LINT-TESTS ### @@ -133,6 +145,17 @@ lint-docker-containers: - ansible-lint $PLAYBOOK_PATH_FOR_ROLE_DOCKER_CONTAINERS allow_failure: false +lint-oh-my-bash: + stage: lint-tests + image: python:3.10.15-bullseye + before_script: + - apt-get update && apt-get install -y python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/* + - pip3 install -r ci-cd/requirements.txt + script: + - echo "Running ansible-lint tests at the role-> 'docker_containers'" + - ansible-lint $PLAYBOOK_PATH_FOR_ROLE_OH_MY_BASH + allow_failure: false + ### ### molecule diff --git a/README.md b/README.md index a01c9d342468c117c73da5ac92d86fa6842d3e2e..ac1cdf8038cd80d924c03c31bb139970be3f3728 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,8 @@ - [x] [dependencies](https://git.cccv.de/fejao/c3infodesk-deployment/-/commit/c04809f7f0644f2cdb1e8affb02ed6c4b623252a) - [x] [clone_repositories](https://git.cccv.de/fejao/c3infodesk-deployment/-/commit/0b9aee5d2d9768b5f77494300e88857b9a3aceee) - [x] [docker_images](https://git.cccv.de/fejao/c3infodesk-deployment/-/commit/a4d532169beed8a18bed536bb1e9a346b6a7b5c0) - - [ ] docker_containers + - [x] [docker_containers](https://git.cccv.de/fejao/c3infodesk-deployment/-/commit/a4d532169beed8a18bed536bb1e9a346b6a7b5c0) + - [x] oh_my_bash ## What is this? diff --git a/ci-cd/06_oh_my_bash.yml b/ci-cd/06_oh_my_bash.yml new file mode 100644 index 0000000000000000000000000000000000000000..836fbfa95d139d6f6ecabdc7f5ba309bfc5e07f5 --- /dev/null +++ b/ci-cd/06_oh_my_bash.yml @@ -0,0 +1,8 @@ +--- +# Runs example for + +- name: CI-CD playbook for running the role 'oh_my_bash' + hosts: + - example_servers_group + roles: + - roles/oh_my_bash diff --git a/playbooks/examples/example_06_oh_my_bash.yml b/playbooks/examples/example_06_oh_my_bash.yml new file mode 100644 index 0000000000000000000000000000000000000000..869f62bb53c8572a7b0cd879c0fe9cb45f4a37fd --- /dev/null +++ b/playbooks/examples/example_06_oh_my_bash.yml @@ -0,0 +1,8 @@ +--- +# Runs example for + +- name: Example playbook for running the role 'oh-my-bash' + hosts: + - example_servers_group + roles: + - roles/oh_my_bash diff --git a/roles/clone_repositories/README.md b/roles/clone_repositories/README.md index 38b58af08c0aa55808d29da20bdb72d39e228b50..f795998a413e50042ecf61927220874367841daa 100644 --- a/roles/clone_repositories/README.md +++ b/roles/clone_repositories/README.md @@ -59,7 +59,7 @@ The role dependencies are: ## Example Playbook - ### Using the provided example - For using the example playbook **[playbooks/examples/example_02_dependencies.yml](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/playbooks/examples/example_02_dependencies.yml)** file you only need to: + For using the example playbook **[playbooks/examples/example_03_clone_repositories.yml](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/playbooks/examples/example_03_clone_repositories.yml)** file you only need to: - Change the user at the **[ansible.cfg](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/ansible.cfg)** file at the field **[remote_user](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/ansible.cfg#L227)** for acessing your target. - Update the file **[inventories/host_vars/example_server.yml](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/inventories/host_vars/example_server.yml)** and change the value for **[ansible_become_pass](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/inventories/host_vars/example_server.yml#L5)** from the **[remote_user](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/ansible.cfg#L227)** - Update the **[inventories/hosts](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/inventories/hosts)** file and change the **[example_server](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/inventories/hosts#L2)** with the IP address from your target. @@ -78,7 +78,7 @@ The role dependencies are: - hosts: - test_servers roles: - - clone_repositories + - roles/clone_repositories ``` And call the playbook as: diff --git a/roles/dependencies/README.md b/roles/dependencies/README.md index 2405938113d27f82ed31dc8fe97e6c1f9b015f34..2d630898335cf08fbd81d59684fa15f989d954c7 100644 --- a/roles/dependencies/README.md +++ b/roles/dependencies/README.md @@ -119,7 +119,7 @@ This role have no dependency from any another role. - hosts: - test_servers roles: - - dependencies + - roles/dependencies ``` And call the playbook as: diff --git a/roles/dependencies/tasks/install_docker.yml b/roles/dependencies/tasks/install_docker.yml index b6403b0c3d8276def05a74e5e6ae329c5b280670..745b0461fa72e89c451a6fc605399ad98e6169c2 100644 --- a/roles/dependencies/tasks/install_docker.yml +++ b/roles/dependencies/tasks/install_docker.yml @@ -11,11 +11,11 @@ paths: - 'vars' -- name: Installing for RedHat OS family +- name: DOCKER | Installing for RedHat OS family ansible.builtin.include_tasks: docker/setup-RedHat.yml when: ansible_os_family == 'RedHat' -- name: Installing for Debian OS family +- name: DOCKER | Installing for Debian OS family ansible.builtin.include_tasks: docker/setup-Debian.yml when: ansible_os_family == 'Debian' diff --git a/roles/docker_containers/README.md b/roles/docker_containers/README.md index f4f2f2af9e7f30a36a21ac45ee8bd0f67d381dad..10fbf22262a0c88fff0c742f5d31a7cc1dcf7f69 100644 --- a/roles/docker_containers/README.md +++ b/roles/docker_containers/README.md @@ -99,7 +99,7 @@ The role dependencies are: The **docker-compose.yml** file can be founded at the location setted from the **c3infodesk_printer_folder** path variable. The default is: **"~/Coding/c3infodesk-printer"** folder - ### Using the provided example - For using the example playbook **[playbooks/examples/example_02_dependencies.yml](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/playbooks/examples/example_02_dependencies.yml)** file you only need to: + For using the example playbook **[playbooks/examples/example_05_docker_containers.yml](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/playbooks/examples/example_05_docker_containers.yml)** file you only need to: - Change the user at the **[ansible.cfg](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/ansible.cfg)** file at the field **[remote_user](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/ansible.cfg#L227)** for acessing your target. - Update the file **[inventories/host_vars/example_server.yml](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/inventories/host_vars/example_server.yml)** and change the value for **[ansible_become_pass](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/inventories/host_vars/example_server.yml#L5)** from the **[remote_user](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/ansible.cfg#L227)** - Update the **[inventories/hosts](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/inventories/hosts)** file and change the **[example_server](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/inventories/hosts#L2)** with the IP address from your target. @@ -126,7 +126,7 @@ The role dependencies are: - hosts: - example_servers_group roles: - - role: docker_containers + - role: roles/docker_containers vars: c3infodesk_printer_host_cups_disable: true c3infodesk_printer_host_cups_mask: true @@ -148,7 +148,7 @@ The role dependencies are: - hosts: - test_servers roles: - - role: docker-containers + - role: roles/docker-containers vars: printer_docker_compose_restart: true ``` @@ -165,7 +165,7 @@ The role dependencies are: - hosts: - test_servers roles: - - docker-containers + - roles/docker-containers ``` And call it passing the variable, for example, restarting the containers from **c3infodesk-printer**. diff --git a/roles/docker_images/README.md b/roles/docker_images/README.md index 0a86c6be85a90222f2739ca758dce77fe01b09c0..9ce6c8772404cae5271bac8241d0d63e0439ecc8 100644 --- a/roles/docker_images/README.md +++ b/roles/docker_images/README.md @@ -81,7 +81,7 @@ The role dependencies are: ## Example Playbook - ### Using the provided example - For using the example playbook **[playbooks/examples/example_02_dependencies.yml](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/playbooks/examples/example_02_dependencies.yml)** file you only need to: + For using the example playbook **[playbooks/examples/example_04_docker_images.yml](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/playbooks/examples/example_04_docker_images.yml)** file you only need to: - Change the user at the **[ansible.cfg](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/ansible.cfg)** file at the field **[remote_user](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/ansible.cfg#L227)** for acessing your target. - Update the file **[inventories/host_vars/example_server.yml](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/inventories/host_vars/example_server.yml)** and change the value for **[ansible_become_pass](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/inventories/host_vars/example_server.yml#L5)** from the **[remote_user](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/ansible.cfg#L227)** - Update the **[inventories/hosts](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/inventories/hosts)** file and change the **[example_server](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/inventories/hosts#L2)** with the IP address from your target. @@ -101,7 +101,7 @@ The role dependencies are: - hosts: - test_servers roles: - - docker_images + - roles/docker_images ``` And call the playbook as: diff --git a/roles/oh_my_bash/README.md b/roles/oh_my_bash/README.md new file mode 100644 index 0000000000000000000000000000000000000000..7ab2512687588fff91a61aad4b9b746983b826cd --- /dev/null +++ b/roles/oh_my_bash/README.md @@ -0,0 +1,126 @@ +# oh_my_bash role + +This ansible-role for installing [oh-my-bash](https://github.com/ohmybash/oh-my-bash) at the **c3infodesk** systems. + +## Requirements +- To have [ansible](https://docs.ansible.com/ansible/latest/installation_guide/installation_distros.html) installed at your system. + + +## Configuration +You need to set some configuration for this to work +- ### ansible.cfg + You have to edit the **ansible.cfg** file to your needs for accessing your target. + - #### remote_user + You need to set the **remote_user** configuration for accessing the target host. + + Example: [remote_user](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/ansible.cfg#L227) + +- ### HOST_VARS + In order to access your target host, you need to create/edit your **inventories/host_vars/<YOUR_HOST_NAME>.yml** + - #### ansible_become_pass + You need to set the **sudo** password from the user setted on **remote_user** for installing packages and etc. at the target. + + Example: [ansible_become_pass](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/inventories/host_vars/example_server.yml#L5) + +- ### HOSTS + You need to provide a **group** in which your target belongs to with the same name setted for **inventories/host_vars/<YOUR_HOST_NAME>.yml**. + + There you can add/edit the target address/IP. + + Example: [hosts](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/inventories/hosts) + + +## Role Variables +Here are the variables setted: + +- ### From: inventories/host_vars/<TARGET_NAME> + No variable setted at this file + +- ### From: inventories/group_vars/<TARGET_GROUP> + No variable setted at this file + +- ### From: roles/clone-repositories/defaults/main.yml + Don't change the values at this file, if you need to change them, change it at the **inventories/host_vars/<TARGET_NAME>** file + - **oh_my_bash_dependencies_list**: DEFAULT=["bash-completion","curl","git","vim"] + - **oh_my_bash_dependencies_state**: DEFAULT=present + - **oh_my_bash_debug**: DEAFULT=false + - **oh_my_bash_download_url**: DEFAULT="https://raw.githubusercontent.com/ohmybash/oh-my-bash/master/tools/install.sh" + - **oh_my_bash_download_dest**: DEAFULT="/tmp/install_ohmybash.sh" + - **oh_my_bash_installed_path**: DEAFULT="~/.oh-my-bash" + - **oh_my_bash_change_theme**: DEAFULT=true + - **oh_my_bash_theme_name**: DEAFULT="pzq" + + +## Dependencies +This role have no dependency from any another role. + + +## Example Playbook + +- ### Using the provided example + For using the example playbook **[playbooks/examples/example_06_oh_my_bash.yml](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/playbooks/examples/example_06_oh_my_bash.yml)** file you only need to: + - Change the user at the **[ansible.cfg](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/ansible.cfg)** file at the field **[remote_user](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/ansible.cfg#L227)** for acessing your target. + - Update the file **[inventories/host_vars/example_server.yml](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/inventories/host_vars/example_server.yml)** and change the value for **[ansible_become_pass](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/inventories/host_vars/example_server.yml#L5)** from the **[remote_user](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/ansible.cfg#L227)** + - Update the **[inventories/hosts](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/inventories/hosts)** file and change the **[example_server](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/inventories/hosts#L2)** with the IP address from your target. + + + And run the command: + ```bash + ansible-playbook -i inventories/hosts playbooks/examples/example_06_oh_my_bash.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: + - roles/oh_my_bash + ``` + + And call the playbook as: + + ```bash + ansible-playbook -i <INVENTORY> <PLAYBOOK_NAME>.yml + ``` + + +## Testing +You can test this locally using **DIND (docker in docker)** at your own computer using [ansible molecule](https://ansible.readthedocs.io/projects/molecule/installation/) + +- ### Testing requirements + You need docker installed at your system and the [ansible molecule](https://ansible.readthedocs.io/projects/molecule/installation/). + + You might have to set DIND at your system, for linux, you can create the file **/etc/docker/daemon.json** + + And add the content and restart docker. + + ```json + { + "exec-opts": ["native.cgroupdriver=systemd"], + "features": { + "buildkit": true + }, + "experimental": true, + "cgroup-parent": "docker.slice" + } + ``` + +- ### Using molecule + Just go to the root of the role **roles/dependencies** and run the command: + + ```bash + molecule test + ``` + + +## License + +MIT / BSD + + +## Author Information + [https://chaos.social/@fejao](https://chaos.social/@fejao) diff --git a/roles/oh_my_bash/defaults/main.yml b/roles/oh_my_bash/defaults/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..7d26b1e3c04c646272371f202a5920567e9272e9 --- /dev/null +++ b/roles/oh_my_bash/defaults/main.yml @@ -0,0 +1,15 @@ +--- +# defaults file for oh-my-bash + +oh_my_bash_dependencies_list: + - "bash-completion" + - "curl" + - "git" +oh_my_bash_dependencies_state: present + +oh_my_bash_debug: false +oh_my_bash_download_url: "https://raw.githubusercontent.com/ohmybash/oh-my-bash/master/tools/install.sh" +oh_my_bash_download_dest: "/tmp/install_ohmybash.sh" +oh_my_bash_installed_path: "~/.oh-my-bash" +oh_my_bash_change_theme: true +oh_my_bash_theme_name: "pzq" diff --git a/roles/oh_my_bash/meta/main.yml b/roles/oh_my_bash/meta/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..beb0677ecaf316ef19f395d7c715bc03040e66ef --- /dev/null +++ b/roles/oh_my_bash/meta/main.yml @@ -0,0 +1,14 @@ +--- + +galaxy_info: + role_name: oh_my_bash + description: Role to install Oh-My-Bash on the target. + author: fejao + company: cccv.de + license: "MIT / BSD" + min_ansible_version: '2.10' + galaxy_tags: [] + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/roles/oh_my_bash/molecule/README.md b/roles/oh_my_bash/molecule/README.md new file mode 100644 index 0000000000000000000000000000000000000000..81b4e594682041e986452b5fb75098d0b27dd499 --- /dev/null +++ b/roles/oh_my_bash/molecule/README.md @@ -0,0 +1,42 @@ +## ansible molecule tests for role: dependencies + + + +## Why to use it +It's allways a good idea to test your things. + +With **ansible molecule** you can test your role locally without the need of using a **real server** but a local **docker container**. + +## Dependencies + +- ### molecule + You need to have [ansible molecule](https://ansible.readthedocs.io/projects/molecule/installation/) installed. + +- ### DIND (docker in docker) + For using the tests, you will to have **docker** installed locally and and set it for using **DIND (docker in docker)** + + + - ### DIND linux + You have to create/edit the file **/etc/docker/daemon.json** with the content: + + ```json + { + "exec-opts": ["native.cgroupdriver=systemd"], + "features": { + "buildkit": true + }, + "experimental": true, + "cgroup-parent": "docker.slice" + } + ``` + + +## Configuration +There's not much for configuring for using the tests + +## Running the tests +For running the **molecule tests** you just need to run the command: + +```bash +molecule test +``` diff --git a/roles/oh_my_bash/molecule/default/converge.yml b/roles/oh_my_bash/molecule/default/converge.yml new file mode 100644 index 0000000000000000000000000000000000000000..ccd0d7e811d461ab56fad26b8c52a3198fc9294b --- /dev/null +++ b/roles/oh_my_bash/molecule/default/converge.yml @@ -0,0 +1,35 @@ +--- + +- name: MOLECULE | Converge + hosts: all + pre_tasks: + - name: MOLECULE | COVERGE | PRE-TASKS | VARIABLES | From -> ../../defaults + ansible.builtin.include_vars: + dir: ../../defaults + depth: 1 + extensions: + - 'yml' + + # - name: MOLECULE | COVERGE | PRE-TASKS | VARIABLES | From -> ../../vars + # ansible.builtin.include_vars: + # dir: ../../vars + # depth: 1 + # extensions: + # - 'yml' + + - name: MOLECULE | COVERGE | PRE-TASKS | VARIABLES | From -> ../../../../inventories/group_vars + ansible.builtin.include_vars: + dir: ../../../../inventories/group_vars + extensions: + - 'yml' + + - name: MOLECULE | COVERGE | PRE-TASKS | VARIABLES | From -> ../../../../inventories/host_vars + ansible.builtin.include_vars: + dir: ../../../../inventories/host_vars + extensions: + - 'yml' + + tasks: + - name: MOLECULE | CONVERGE | Call the 'oh_my_bash' role. + ansible.builtin.include_role: + name: oh_my_bash diff --git a/roles/oh_my_bash/molecule/default/molecule.yml b/roles/oh_my_bash/molecule/default/molecule.yml new file mode 100644 index 0000000000000000000000000000000000000000..62cffd6746e5268735e4f5fd234dd29deaffef0e --- /dev/null +++ b/roles/oh_my_bash/molecule/default/molecule.yml @@ -0,0 +1,68 @@ +--- + +dependency: + name: galaxy + +driver: + name: docker + +platforms: + - name: molecule_oh_my_bash + ### At the moment I'm not running at the latest kernel, please use always with a older kernel than the host + # image: docker.io/geerlingguy/docker-ubuntu2204-ansible + image: geerlingguy/docker-ubuntu2204-ansible:latest + command: /usr/sbin/init + pre_build_image: true + cgroupns_mode: host + privileged: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + - /var/lib/containerd + +provisioner: + name: ansible + +lint: | + ansible-lint --exclude molecule/default/ + +scenario: + name: default + create_sequence: + - dependency + - create + - prepare + check_sequence: + - dependency + - cleanup + - destroy + - create + - prepare + - converge + - check + - destroy + converge_sequence: + - dependency + - create + - prepare + - converge + destroy_sequence: + - dependency + - cleanup + - destroy + test_sequence: + # - lint + # - dependency + # - cleanup + - destroy + - syntax + - create + # - prepare + - converge + - verify + - idempotence + # - side_effect + # - cleanup + - destroy + +verifier: + name: ansible diff --git a/roles/oh_my_bash/molecule/default/verify.yml b/roles/oh_my_bash/molecule/default/verify.yml new file mode 100644 index 0000000000000000000000000000000000000000..5442deec9e8fc74809169028d54814dda50e0fcc --- /dev/null +++ b/roles/oh_my_bash/molecule/default/verify.yml @@ -0,0 +1,81 @@ +--- + +- name: VERIFY | Test role for debugging variables + hosts: all + pre_tasks: + - name: MOLECULE | VERIFY | PRE-TASKS | VARIABLES | From -> ../../defaults + ansible.builtin.include_vars: + dir: ../../defaults + depth: 1 + extensions: + - 'yml' + + - name: MOLECULE | VERIFY | PRE-TASKS | VARIABLES | From -> ../../../../inventories/group_vars + ansible.builtin.include_vars: + dir: ../../../../inventories/group_vars + extensions: + - 'yml' + + - name: MOLECULE | VERIFY | PRE-TASKS | VARIABLES | From -> ../../../../inventories/host_vars + ansible.builtin.include_vars: + dir: ../../../../inventories/host_vars + extensions: + - 'yml' + + tasks: + ### + ### POPULATE + ### + - name: MOLECULE | VERIFY | POPULATE | Gather the package facts + ansible.builtin.package_facts: + manager: auto + + ## + ## TESTS - PACKAGES + ## + - name: MOLECULE | VERIFY | TEST | Check that the packages from 'oh_my_bash_dependencies_list' are installed. + ansible.builtin.debug: + msg: "Package: '{{ package_name }}' is installed" + loop: "{{ oh_my_bash_dependencies_list }}" + loop_control: + loop_var: package_name + failed_when: package_name not in ansible_facts.packages + + ### + ### TESTS - CHECK INSTALL + ### + - name: MOLECULE | VERIFY | TEST | Oh-My-Bash installed. + ansible.builtin.stat: + path: "{{ oh_my_bash_installed_path }}" + register: check_installed + failed_when: + - not check_installed.stat.exists + + # - name: MOLECULE | VERIFY | TEST | DEBUG | Oh-My-Bash installed. + # ansible.builtin.debug: + # msg: "{{ check_installed }}" + + - name: MOLECULE | VERIFY | TEST | Oh-My-Bash is enabled. + ansible.builtin.lineinfile: + path: "{{ ansible_env.HOME }}/.bashrc" + line: "export OSH='/root/.oh-my-bash'" + state: present + check_mode: true + register: check_enabled + failed_when: check_enabled.changed | bool + + # - name: MOLECULE | VERIFY | TEST | DEBUG | Oh-My-Bash is enabled. + # ansible.builtin.debug: + # msg: "{{ check_enabled }}" + + - name: MOLECULE | VERIFY | TEST | Theme is setted. + ansible.builtin.lineinfile: + path: "{{ ansible_env.HOME }}/.bashrc" + line: 'OSH_THEME="{{ oh_my_bash_theme_name }}"' + state: present + check_mode: true + register: check_theme_set + failed_when: check_theme_set.changed | bool + when: + - oh_my_bash_theme_name is defined + - not check_enabled.changed | bool diff --git a/roles/oh_my_bash/tasks/change_theme.yml b/roles/oh_my_bash/tasks/change_theme.yml new file mode 100644 index 0000000000000000000000000000000000000000..409c5c14f249b94d78751824302745473177c9d1 --- /dev/null +++ b/roles/oh_my_bash/tasks/change_theme.yml @@ -0,0 +1,35 @@ +--- +# tasks for changing oh-my-bash theme + +### CHECK +- name: THEME | CHECK | Test Oh-My-Bash installation. + ansible.builtin.stat: + path: "{{ oh_my_bash_installed_path }}" + register: install_check + +- name: THEME | CHECK | Test theme installation. + ansible.builtin.lineinfile: + path: "{{ ansible_env.HOME }}/.bashrc" + # line: 'OSH_THEME="pzq"' + line: 'OSH_THEME="{{ oh_my_bash_theme_name }}"' + state: present + check_mode: true + register: theme_installed + when: + - oh_my_bash_theme_name is defined + - install_check.stat.exists | bool + +- name: THEME | CHECK | Test theme installation response. + ansible.builtin.debug: + msg: "{{ 'Theme not installed, installing...' if theme_installed.changed else 'Theme already installed...' }}" + +### INSTALL +- name: THEME | CHANGE | Set the Theme. + ansible.builtin.lineinfile: + path: "{{ ansible_env.HOME }}/.bashrc" + regexp: '^.*OSH_THEME=.*$' + # insertafter: '^OSH_THEME' + line: OSH_THEME="{{ oh_my_bash_theme_name }}" + when: + - oh_my_bash_theme_name is defined + - theme_installed.changed | bool diff --git a/roles/oh_my_bash/tasks/install_dependencies.yml b/roles/oh_my_bash/tasks/install_dependencies.yml new file mode 100644 index 0000000000000000000000000000000000000000..a83260a1d0c74d5ee079008551140ab4ea961caa --- /dev/null +++ b/roles/oh_my_bash/tasks/install_dependencies.yml @@ -0,0 +1,11 @@ +--- + +- name: DEPENDENCIES | Installing the packages from list + ansible.builtin.package: + name: "{{ package_name }}" + state: "{{ oh_my_bash_dependencies_state }}" + update_cache: true + loop: "{{ oh_my_bash_dependencies_list }}" + loop_control: + loop_var: package_name + become: true diff --git a/roles/oh_my_bash/tasks/install_oh_my_bash.yml b/roles/oh_my_bash/tasks/install_oh_my_bash.yml new file mode 100644 index 0000000000000000000000000000000000000000..d432dab2ee007c69cbad03e36b5e3adc7d3754b4 --- /dev/null +++ b/roles/oh_my_bash/tasks/install_oh_my_bash.yml @@ -0,0 +1,39 @@ +--- +# tasks file for oh-my-bash + + +### CHECK INSTALL +- name: INSTALL | Test Oh-My-Bash installation. + ansible.builtin.stat: + path: "{{ oh_my_bash_installed_path }}" + register: check_if_installed + +- name: INSTALL | Check if Oh-My-Bash already installed. + ansible.builtin.debug: + msg: "{{ 'Oh-My-Bash already installed' if check_if_installed.stat.exists == True else 'Oh-My-Bash not installed, installing...' }}" + +### DOWNLOAD +- name: INSTALL | Download installation script. + ansible.builtin.get_url: + url: "{{ oh_my_bash_download_url }}" + dest: "{{ oh_my_bash_download_dest }}" + mode: "0777" + register: install_script_downloaded + when: + - check_if_installed is defined + - not check_if_installed.stat.exists | bool + +### INSTALL +- name: INSTALL | Runs the installation script. + ansible.builtin.command: + cmd: "{{ oh_my_bash_download_dest }} --unattended" + vars: + ansible_command_timeout: 15 + register: install_result + when: + - install_script_downloaded.failed is defined + - not install_script_downloaded.failed | bool + changed_when: install_result.rc != 0 + +- name: INSTALL | Reset ssh connection to apply user changes. + ansible.builtin.meta: reset_connection diff --git a/roles/oh_my_bash/tasks/main.yml b/roles/oh_my_bash/tasks/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..0cdcc080abf550d6cca15b1ec4eaa2e48b609d60 --- /dev/null +++ b/roles/oh_my_bash/tasks/main.yml @@ -0,0 +1,12 @@ +--- +# tasks file for oh-my-bash + +- name: Install dependencies + ansible.builtin.import_tasks: install_dependencies.yml + +- name: Install Oh-My-Bash + ansible.builtin.import_tasks: install_oh_my_bash.yml + +- name: Change Theme + ansible.builtin.import_tasks: change_theme.yml + when: oh_my_bash_change_theme | bool