diff --git a/.github/workflows/ansible_valida_role.yaml b/.github/workflows/ansible_valida_role.yaml new file mode 100644 index 0000000..916e2c9 --- /dev/null +++ b/.github/workflows/ansible_valida_role.yaml @@ -0,0 +1,66 @@ +--- +name: "Valida Roles Ansible" + +on: + workflow_call: + inputs: + python_version: + description: "Versão do python" + required: false + type: string + default: '3.9' + os_version: + description: "Versão do sistema operacional" + required: false + default: "ubuntu-20.04" + type: string + secrets: + token: + required: true +jobs: + linter: + runs-on: ${{ inputs.os_version }} + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ inputs.python_version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ inputs.python_version }} + - name: Install dependencies + run: | + python3 -m pip install --upgrade pip + python3 -m pip install -r requirements.txt + - name: Run Linters + run: | + ansible-lint + + molecule: + runs-on: ${{ inputs.os_version }} + strategy: + matrix: + molecule_distro: [ubuntu1804, ubuntu2004] + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ inputs.python_version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ inputs.python_version }} + - name: Install dependencies + run: | + python3 -m pip install --upgrade pip + python3 -m pip install -r requirements.txt + - name: Force GitHub Actions' docker daemon to use vfs. + run: | + sudo systemctl stop docker + echo '{"cgroup-parent":"/actions_job","storage-driver":"vfs"}' | sudo tee /etc/docker/daemon.json + sudo systemctl start docker + - name: Test with molecule + run: | + molecule test --all + env: + PY_COLORS: '1' + ANSIBLE_FORCE_COLOR: '1' + # Mudar a cor de mensagens de debug para aparecer melhor no fundo + # escuro dos logs do GitHub Action. + ANSIBLE_COLOR_DEBUG: "bright gray" + MOLECULE_DISTRO: ${{ matrix.molecule_distro }} diff --git a/docs/ansible_valida_role.md b/docs/ansible_valida_role.md new file mode 100644 index 0000000..9750131 --- /dev/null +++ b/docs/ansible_valida_role.md @@ -0,0 +1,31 @@ +# Ansible Valida Role +Github Actions para ser reutilizado nos projetos de Ansible. Faz a validação da sintaxe da role Ansible. + +## Inputs +| Nome | Descrição | Requirida |Default | +|------|-----------|-----------|--------| +|`python_version` | Versão do python | não | 3.9 | +|`os_version` | Versão do sistema operacional | não | ubuntu-20.04 | + + +## Utilizando +Criar a seguintes estrutura de diretórios: + +`.github/workflows/.yml` + +Utilize o exemplo abaixo para seu pipeline de CI: + +```yaml +name: "Valida role ansible" + +on: + push: + branches: + - main + pull_request: +jobs: + valida: + uses: "mentoriaiac/cicd_centralizado/.github/workflows/ansible_valida_role.yaml@v1" + secrets: + token: ${{ secrets.TOKEN }} +```