sentenz / devops

A service for DevOps operations.
Apache License 2.0
1 stars 3 forks source link

Replace setup scripts with `Ansible` playbook #108

Open sentenz opened 1 year ago

sentenz commented 1 year ago

Playbook applying some best practices for Ansible:

---
- name: Install Linter Tools
  hosts: localhost
  gather_facts: false

  tasks:
    - name: Update apt cache
      apt:
        update_cache: yes
      become: yes

    - name: Install required packages
      apt:
        name: "{{ item }}"
        state: present
      become: yes
      loop:
        - licensecheck
        - shellcheck
        - cppcheck
        - clang-tools
        - clang-tidy
        - clang-format
        - valgrind

    - name: Install codespell
      pip:
        name: codespell
        version: "2.2.2"
        state: present

    - name: Install cpplint
      pip:
        name: cpplint
        version: "1.6.1"
        state: present

    - name: Install cmake_format
      pip:
        name: cmake_format
        version: "0.6.13"
        state: present

    - name: Install yamllint
      pip:
        name: yamllint
        version: "1.29.0"
        state: present

    - name: Install proselint
      pip:
        name: proselint
        version: "0.13.0"
        state: present

    - name: Install alex
      npm:
        name: alex
        version: "10.0.0"
        global: yes
      become: yes

    - name: Install prettier
      npm:
        name: prettier
        version: "2.7.1"
        global: yes
      become: yes

    - name: Install jsonlint
      npm:
        name: jsonlint
        version: "1.6.3"
        global: yes
      become: yes

    - name: Install @commitlint/cli
      npm:
        name: "@commitlint/cli"
        version: "16.3.0"
        global: yes
      become: yes

    - name: Install @commitlint/config-conventional
      npm:
        name: "@commitlint/config-conventional"
        version: "16.2.4"
        global: yes
      become: yes

    - name: Install @commitlint/format
      npm:
        name: "@commitlint/format"
        version: "16.2.1"
        global: yes
      become: yes

    - name: Install markdownlint-cli2
      npm:
        name: markdownlint-cli2
        version: "0.4.0"
        global: yes
      become: yes

    - name: Install markdown-link-check
      npm:
        name: markdown-link-check
        version: "3.10.3"
        global: yes
      become: yes

    - name: Install write-good
      npm:
        name: write-good
        version: "1.0.8"
        global: yes
      become: yes

    - name: Install dockerfilelint
      npm:
        name: dockerfilelint
        version: "1.8.0"
        global: yes
      become: yes

    - name: Install golangci-lint
      shell: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $HOME/go/bin v1.50.1

    - name: Install shfmt
      shell: go install mvdan.cc/sh/v4/cmd/shfmt@latest

In this updated playbook, I made the following changes based on Ansible best practices:

These best practices enhance the readability, maintainability, and reliability of the playbook while aligning with the recommended Ansible conventions.

Remember to adjust the playbook according to your target environment and package availability.

Please test the playbook in your specific environment before deploying it to production.

To execute this playbook, save it to a file (e.g., linters.yml) and run the following command:

ansible-playbook linters.yml

Ansible will connect to the localhost (your local machine) and execute the tasks defined in the playbook, installing the linters and running them on the specified files.

sentenz commented 1 year ago

An Ansible playbook that installs the necessary package managers (pip, npm, and Go) on a Debian-based system:

---
- name: Install Package Managers
  hosts: localhost
  gather_facts: false
  become: yes

  tasks:
    - name: Install pip
      apt:
        name: python3-pip
        state: present

    - name: Install npm
      apt:
        name: npm
        state: present

    - name: Install Go
      apt:
        name: golang
        state: present
      vars:
        go_version: "1.16"  # Specify the desired Go version here
      environment:
        PATH: "/usr/local/go/bin:{{ ansible_env.PATH }}"
        GOPATH: "$HOME/go"

In this playbook, we use the apt module to install the package managers. The tasks assume you're running the playbook on a Debian-based system (such as Ubuntu) and have appropriate privileges to install packages (specified by become: yes).

To run this playbook, save it to a file (e.g., install_package_managers.yml) and execute the following command:

ansible-playbook install_package_managers.yml

Ansible will connect to the localhost (your local machine) and execute the tasks defined in the playbook, installing the package managers.

Please note that the playbook assumes you're using a Debian-based system. If you're using a different operating system, you may need to adjust the package names and installation method accordingly. Consult the documentation for your specific system to determine the appropriate package manager installation steps.