Skip to content
Snippets Groups Projects
Commit 4d2a29cd authored by fejao's avatar fejao
Browse files

Merge branch 'Adding_files' into 'main'

Adding files

See merge request !1
parents 996a96bd 5c8192d4
No related branches found
No related tags found
1 merge request!1Adding files
Pipeline #37889 passed
Pipeline: c3infodesk-deployment

#37890

    *OLD*
    ---
    ###
    ### VARIABLES
    ###
    variables:
    AUTHOR: fejao
    IMAGE_NAME_LINT: python:3.10.15-bullseye
    PATH_ENV_DIR: "/builds/fejao/c3infodesk-deployment-role-oh-my-bash"
    PATH_PYTHON_REQ_FILE: "/builds/fejao/c3infodesk-deployment-role-oh-my-bash/ci-cd/python_requirements.txt"
    ###
    ### STAGES
    ###
    stages:
    - yamllint
    - upstream-trigger
    ###
    ### SCRIPTS
    ###
    .install_dependencies: &install_dependencies
    # Install python and it's requirements
    - apt-get update && apt-get install -y python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/*
    - pip3 install -r $PYTHON_REQ_FILE_PATH
    ### Correct the permissions on the build environment directory.
    ### See https://github.com/ansible/ansible/pull/42142/files
    - chmod 700 $PATH_ENV_DIR
    yamllint-test:
    stage: yamllint
    image: $IMAGE_NAME_LINT
    variables:
    PYTHON_REQ_FILE_PATH: $PATH_PYTHON_REQ_FILE
    before_script:
    - *install_dependencies
    script:
    - echo "This is the 'yamllint' test from the 'oh-my-bash' role"
    - yamllint .
    trigger-pipeline:
    stage: upstream-trigger
    variables:
    RUN_UPSTREAM_FOR_ROLE_OH_MY_BASH: true
    trigger:
    project: fejao/c3infodesk-deployment
    branch: main
    strategy: depend
    ---
    # https://ansible.readthedocs.io/projects/lint/rules/yaml/
    yaml-files:
    - '*.yaml'
    - '*.yml'
    - '.yamllint'
    rules:
    anchors: enable
    # braces: enable
    # braces: disable
    braces:
    max-spaces-inside: 1
    brackets: enable
    colons: enable
    commas: enable
    comments:
    level: warning
    min-spaces-from-content: 1
    comments-indentation: false
    document-end: disable
    document-start:
    level: warning
    empty-lines: enable
    empty-values: disable
    float-values: disable
    hyphens: enable
    # indentation: enable
    indentation: disable
    key-duplicates: enable
    key-ordering: disable
    # line-length: enable
    line-length:
    # max: 160
    ### roles/dependencies/defaults/main.yml:72 --> 232 characters
    max: 240
    new-line-at-end-of-file: enable
    new-lines: enable
    # octal-values: disable
    quoted-strings: disable
    trailing-spaces: enable
    truthy:
    level: warning
    ####
    # var_naming_pattern: "^[a-z_][a-z0-9_]*$"
    # var-naming: disable
    # var-naming:
    # no-role-prefix: disable
    # c3infodesk-deployment-role-oh-my-bash # 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.
    ## Getting started
    To make it easy for you to get started with GitLab, here's a list of recommended next steps. ## 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.
    Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! Example: [remote_user](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/ansible.cfg#L227)
    ## Add your files - ### 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.
    - [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files Example: [ansible_become_pass](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/inventories/host_vars/example_server.yml#L5)
    - [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
    ``` - ### HOSTS
    cd existing_repo 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**.
    git remote add origin https://git.cccv.de/fejao/c3infodesk-deployment-role-oh-my-bash.git
    git branch -M main
    git push -uf origin main
    ```
    ## Integrate with your tools There you can add/edit the target address/IP.
    - [ ] [Set up project integrations](https://git.cccv.de/fejao/c3infodesk-deployment-role-oh-my-bash/-/settings/integrations) Example: [hosts](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/inventories/hosts)
    ## Collaborate with your team
    - [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) ## Role Variables
    - [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) Here are the variables setted:
    - [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
    - [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
    - [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
    ## Test and Deploy - ### From: inventories/host_vars/<TARGET_NAME>
    No variable setted at this file
    Use the built-in continuous integration in GitLab. - ### From: inventories/group_vars/<TARGET_GROUP>
    No variable setted at this file
    - [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) - ### From: roles/clone-repositories/defaults/main.yml
    - [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) Don't change the values at this file, if you need to change them, change it at the **inventories/host_vars/<TARGET_NAME>** file
    - [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) - **oh_my_bash_dependencies_list**: DEFAULT=["bash-completion","curl","git","vim"]
    - [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) - **oh_my_bash_dependencies_state**: DEFAULT=present
    - [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) - **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"
    ***
    # Editing this README ## Dependencies
    This role have no dependency from any another role.
    When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
    ## Suggestions for a good README ## Example Playbook
    Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. - ### 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.
    ## Name
    Choose a self-explaining name for your project.
    ## Description And run the command:
    Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. ```bash
    ansible-playbook -i inventories/hosts playbooks/examples/example_06_oh_my_bash.yml
    ```
    ## Badges - ### Setting your own example
    On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. After setting your variables at **inventories/host_vars/<HOST_NAME>**, you can add this role to your playbook as a regular role.
    ## Visuals Here is an example using the **<HOST_NAME>** as **test_servers**
    Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
    ## Installation ```yaml
    Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. - hosts:
    - test_servers
    roles:
    - roles/c3infodesk-deployment-role-oh-my-bash
    ```
    ## Usage And call the playbook as:
    Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
    ```bash
    ansible-playbook -i <INVENTORY> <PLAYBOOK_NAME>.yml
    ```
    ## Support
    Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
    ## Roadmap ## Testing
    If you have ideas for releases in the future, it is a good idea to list them in the README. You can test this locally using **DIND (docker in docker)** at your own computer using [ansible molecule](https://ansible.readthedocs.io/projects/molecule/installation/)
    ## Contributing - ### Testing requirements
    State if you are open to contributions and what your requirements are for accepting them. You need docker installed at your system and the [ansible molecule](https://ansible.readthedocs.io/projects/molecule/installation/).
    For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. You might have to set DIND at your system, for linux, you can create the file **/etc/docker/daemon.json**
    You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. 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
    ```
    ## Authors and acknowledgment
    Show your appreciation to those who have contributed to the project.
    ## License ## License
    For open source projects, say how it is licensed.
    ## Project status MIT / BSD
    If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
    ## Author Information
    [https://chaos.social/@fejao](https://chaos.social/@fejao)
    yamllint
    ---
    # 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"
    ---
    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.
    ## 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
    ```
    ---
    - 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 -> ../../../../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
    name: c3infodesk-deployment-role-oh-my-bash
    ---
    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
    ---
    - 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 | 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 | 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
    ---
    # 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
    ---
    - 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
    ---
    # 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
    ---
    # 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
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please to comment