|
| 1 | +--- |
| 2 | + |
| 3 | +# This is a basic workflow to help you get started with Actions |
| 4 | + |
| 5 | +name: Devel Pipeline Validation |
| 6 | + |
| 7 | +# Controls when the action will run. |
| 8 | +# Triggers the workflow on push or pull request |
| 9 | +# events but only for the devel branch |
| 10 | +on: # yamllint disable-line rule:truthy |
| 11 | + pull_request_target: |
| 12 | + types: [opened, reopened, synchronize] |
| 13 | + branches: |
| 14 | + - devel |
| 15 | + paths: |
| 16 | + - '**.yml' |
| 17 | + - '**.sh' |
| 18 | + - '**.j2' |
| 19 | + - '**.ps1' |
| 20 | + - '**.cfg' |
| 21 | + |
| 22 | +# A workflow run is made up of one or more jobs that can run sequentially or in parallel |
| 23 | +# This section contains all the jobs below that are running in the workflow. |
| 24 | +jobs: |
| 25 | + # This will create messages for the first time contributors and direct them to the Discord server |
| 26 | + welcome: |
| 27 | + # The type of runner that the job will run on. |
| 28 | + runs-on: ubuntu-latest |
| 29 | + steps: |
| 30 | + - uses: actions/first-interaction@main |
| 31 | + with: |
| 32 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 33 | + pr-message: |- |
| 34 | + Congrats on opening your first pull request and thank you for taking the time to help improve Ansible-Lockdown! |
| 35 | + Please join in the conversation happening on the [Discord Server](https://www.lockdownenterprise.com/discord) as well. |
| 36 | +
|
| 37 | + # This workflow will run Terraform to load an instance in Azure to test the playbook against a live cloud-based instance. |
| 38 | + playbook-test: |
| 39 | + # The type of runner that the job will run on. |
| 40 | + runs-on: ubuntu-latest |
| 41 | + |
| 42 | + env: |
| 43 | + ENABLE_DEBUG: false |
| 44 | + # Imported as a variable by terraform. |
| 45 | + TF_VAR_repository: ${{ github.event.repository.name }} |
| 46 | + ARM_CLIENT_ID: ${{ secrets.AZURE_AD_CLIENT_ID }} |
| 47 | + ARM_CLIENT_SECRET: ${{ secrets.AZURE_AD_CLIENT_SECRET }} |
| 48 | + ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} |
| 49 | + ARM_TENANT_ID: ${{ secrets.AZURE_AD_TENANT_ID }} |
| 50 | + WIN_USERNAME: ${{ secrets.WIN_USERNAME }} |
| 51 | + WIN_PASSWORD: ${{ secrets.WIN_PASSWORD }} |
| 52 | + |
| 53 | + defaults: |
| 54 | + run: |
| 55 | + shell: bash |
| 56 | + working-directory: .github/workflows/github_windows_IaC |
| 57 | + |
| 58 | + # Steps represent a sequence of tasks that will be executed as part of the job. |
| 59 | + steps: |
| 60 | + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it. |
| 61 | + - name: Clone ${{ github.event.repository.name }} |
| 62 | + uses: actions/checkout@v3 |
| 63 | + with: |
| 64 | + ref: ${{ github.event.pull_request.head.sha }} |
| 65 | + |
| 66 | + # Pull In Terraform Code For Windows Azure |
| 67 | + - name: Clone github IaC plan |
| 68 | + uses: actions/checkout@v3 |
| 69 | + with: |
| 70 | + repository: ansible-lockdown/github_windows_IaC |
| 71 | + path: .github/workflows/github_windows_IaC |
| 72 | + |
| 73 | + # Sensitive Data Stored And Passed To Terraform |
| 74 | + # Default Working Dir Defined In Defaults Above. |
| 75 | + - name: user details |
| 76 | + run: echo "{\"username\":\"${WIN_USERNAME}\",\"password\":\"${WIN_PASSWORD}\"}" >> sensitive_info.json |
| 77 | + |
| 78 | + # Show the Os Var and Benchmark Type And Load |
| 79 | + - name: DEBUG - Show IaC files |
| 80 | + if: env.ENABLE_DEBUG == 'true' |
| 81 | + run: | |
| 82 | + echo "OSVAR = $OSVAR" |
| 83 | + echo "benchmark_type = $benchmark_type" |
| 84 | + pwd |
| 85 | + ls |
| 86 | + env: |
| 87 | + # Imported from github variables this is used to load the relevant OS.tfvars file |
| 88 | + OSVAR: ${{ vars.OSVAR }} |
| 89 | + TF_VAR_benchmark_type: ${{ vars.BENCHMARK_TYPE }} |
| 90 | + |
| 91 | + # Initialize The Terraform Working Directory |
| 92 | + - name: Terraform_Init |
| 93 | + id: init |
| 94 | + run: terraform init |
| 95 | + env: |
| 96 | + # Imported from github variables this is used to load the relevant OS.tfvars file |
| 97 | + OSVAR: ${{ vars.OSVAR }} |
| 98 | + TF_VAR_benchmark_type: ${{ vars.BENCHMARK_TYPE }} |
| 99 | + |
| 100 | + # Validate The Syntax Of Terraform Files |
| 101 | + - name: Terraform_Validate |
| 102 | + id: validate |
| 103 | + run: terraform validate |
| 104 | + env: |
| 105 | + # Imported from github variables this is used to load the relevant OS.tfvars file |
| 106 | + OSVAR: ${{ vars.OSVAR }} |
| 107 | + TF_VAR_benchmark_type: ${{ vars.BENCHMARK_TYPE }} |
| 108 | + |
| 109 | + # Execute The Actions And Build Azure Server |
| 110 | + - name: Terraform_Apply |
| 111 | + id: apply |
| 112 | + env: |
| 113 | + # Imported from github variables this is used to load the relevant OS.tfvars file |
| 114 | + WIN_USERNAME: ${{ secrets.WIN_USERNAME }} |
| 115 | + WIN_PASSWORD: ${{ secrets.WIN_PASSWORD }} |
| 116 | + OSVAR: ${{ vars.OSVAR }} |
| 117 | + TF_VAR_benchmark_type: ${{ vars.BENCHMARK_TYPE }} |
| 118 | + run: terraform apply -var-file "${OSVAR}.tfvars" --auto-approve |
| 119 | + |
| 120 | + # Debug Section |
| 121 | + - name: DEBUG - Show Ansible Hostfile |
| 122 | + if: env.ENABLE_DEBUG == 'true' |
| 123 | + run: cat hosts.yml |
| 124 | + |
| 125 | + # Run the Ansible Playbook |
| 126 | + - name: Run_Ansible_Playbook |
| 127 | + uses: arillso/action.playbook@master |
| 128 | + with: |
| 129 | + playbook: site.yml |
| 130 | + inventory: .github/workflows/github_windows_IaC/hosts.yml |
| 131 | + galaxy_file: collections/requirements.yml |
| 132 | + # verbose: 3 |
| 133 | + env: |
| 134 | + ANSIBLE_HOST_KEY_CHECKING: "false" |
| 135 | + ANSIBLE_DEPRECATION_WARNINGS: "false" |
| 136 | + |
| 137 | + # Destroy The Azure Test System |
| 138 | + - name: Terraform_Destroy |
| 139 | + if: always() && env.ENABLE_DEBUG == 'false' |
| 140 | + env: |
| 141 | + OSVAR: ${{ vars.OSVAR }} |
| 142 | + TF_VAR_benchmark_type: ${{ vars.BENCHMARK_TYPE }} |
| 143 | + run: terraform destroy -var-file "${OSVAR}.tfvars" --auto-approve |
0 commit comments