|
| 1 | +# This is a basic workflow to help you get started with Actions |
| 2 | + |
| 3 | +name: linux_benchmark_pipeline |
| 4 | + |
| 5 | +# Controls when the action will run. |
| 6 | +# Triggers the workflow on push or pull request |
| 7 | +# events but only for the devel branch |
| 8 | +on: # yamllint disable-line rule:truthy |
| 9 | + pull_request_target: |
| 10 | + types: [opened, reopened, synchronize] |
| 11 | + branches: |
| 12 | + - devel |
| 13 | + - main |
| 14 | + paths: |
| 15 | + - '**.yml' |
| 16 | + - '**.sh' |
| 17 | + - '**.j2' |
| 18 | + - '**.ps1' |
| 19 | + - '**.cfg' |
| 20 | + |
| 21 | +# A workflow run is made up of one or more jobs |
| 22 | +# that can run sequentially or in parallel |
| 23 | +jobs: |
| 24 | + # This will create messages for first time contributers and direct them to the Discord server |
| 25 | + welcome: |
| 26 | + runs-on: ubuntu-latest |
| 27 | + |
| 28 | + steps: |
| 29 | + - uses: actions/first-interaction@main |
| 30 | + with: |
| 31 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 32 | + pr-message: |- |
| 33 | + Congrats on opening your first pull request and thank you for taking the time to help improve Ansible-Lockdown! |
| 34 | + Please join in the conversation happening on the [Discord Server](https://discord.io/ansible-lockdown) as well. |
| 35 | + # This workflow contains a single job called "build" |
| 36 | + build: |
| 37 | + # The type of runner that the job will run on |
| 38 | + runs-on: ubuntu-latest |
| 39 | + defaults: |
| 40 | + run: |
| 41 | + shell: bash |
| 42 | + working-directory: .github/workflows/github_linux_IaC |
| 43 | + |
| 44 | + env: |
| 45 | + ENABLE_DEBUG: false |
| 46 | + # Imported as a variable by terraform |
| 47 | + TF_VAR_repository: ${{ github.event.repository.name }} |
| 48 | + # Imported from github variables this is used to load the relvent OS.tfvars file |
| 49 | + OSVAR: ${{ env.OSVAR }} |
| 50 | + BENCHMARK_TYPE: ${{ env.BENCHMARK_TYPE }} |
| 51 | + |
| 52 | + # Steps represent a sequence of tasks that will be executed as part of the job |
| 53 | + steps: |
| 54 | + # Checks-out your repository under $GITHUB_WORKSPACE, |
| 55 | + # so your job can access it |
| 56 | + - name: Clone ${{ github.event.repository.name }} |
| 57 | + uses: actions/checkout@v3 |
| 58 | + with: |
| 59 | + ref: ${{ github.event.pull_request.head.sha }} |
| 60 | + |
| 61 | + # Pull in terraform code for linux servers |
| 62 | + - name: Clone github IaC plan |
| 63 | + uses: actions/checkout@v3 |
| 64 | + with: |
| 65 | + respository: ansible-lockdown/github_linux_IaC |
| 66 | + path: github_linux_IaC |
| 67 | + |
| 68 | + - name: Add_ssh_key |
| 69 | + working-directory: .github/workflows |
| 70 | + env: |
| 71 | + SSH_AUTH_SOCK: /tmp/ssh_agent.sock |
| 72 | + PRIVATE_KEY: "${{ secrets.SSH_PRV_KEY }}" |
| 73 | + run: | |
| 74 | + mkdir .ssh |
| 75 | + chmod 700 .ssh |
| 76 | + echo $PRIVATE_KEY > .ssh/github_actions.pem |
| 77 | + chmod 600 .ssh/github_actions.pem |
| 78 | +
|
| 79 | +### Build out the server |
| 80 | + |
| 81 | + - name: Terraform_Init |
| 82 | + id: init |
| 83 | + run: terraform init |
| 84 | + |
| 85 | + - name: Terraform_Validate |
| 86 | + id: validate |
| 87 | + run: terraform validate |
| 88 | + |
| 89 | + - name: Terraform_Apply |
| 90 | + id: apply |
| 91 | + env: |
| 92 | + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 93 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 94 | + run: terraform apply -var-file "github_vars.tfvars" -var-file "${OSVAR}.tfvars" --auto-approve -input=false |
| 95 | + |
| 96 | + ## Debug Section |
| 97 | + - name: DEBUG - Show Ansible hostfile |
| 98 | + if: env.ENABLE_DEBUG == 'true' |
| 99 | + run: cat hosts.yml |
| 100 | + |
| 101 | + # Aws deployments taking a while to come up insert sleep or playbook fails |
| 102 | + |
| 103 | + - name: Sleep for 60 seconds |
| 104 | + run: sleep 60s |
| 105 | + shell: bash |
| 106 | + |
| 107 | + # Run the ansible playbook |
| 108 | + - name: Run_Ansible_Playbook |
| 109 | + uses: arillso/action.playbook@master |
| 110 | + with: |
| 111 | + playbook: site.yml |
| 112 | + inventory: .github/workflows/github_IaC/hosts.yml |
| 113 | + galaxy_file: collections/requirements.yml |
| 114 | + private_key: ${{ secrets.SSH_PRV_KEY }} |
| 115 | + # verbose: 3 |
| 116 | + env: |
| 117 | + ANSIBLE_HOST_KEY_CHECKING: "false" |
| 118 | + ANSIBLE_DEPRECATION_WARNINGS: "false" |
| 119 | + |
| 120 | + # Remove test system - User secrets to keep if necessary |
| 121 | + |
| 122 | + - name: Terraform_Destroy |
| 123 | + if: always() && env.ENABLE_DEBUG == 'false' |
| 124 | + env: |
| 125 | + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 126 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 127 | + run: terraform destroy -var-file "github_vars.tfvars" -var-file "${OSVAR}.tfvars" --auto-approve -input=false |
0 commit comments