I'm running some Ansible playbooks from a self hosted runner to deploy websites and need to send the results via email. I'm using a manually triggered workflow_dispatch event with one custom user input argument to start everything and the dawidd6/action-send-mail@v3 action to send the email (https://github.com/marketplace/actions/send-email).
I able to access the argument from user input in the first step that runs the Ansible playbooks, but not in the next step to send the email. The Ansible playbooks run and the email sends successfully, but I can't get the specific user supplied variable into the email.
I've tried accessing it directly in the github.event.inputs. context, which works in the Ansible playbooks step, saving that to a variable and accessing that, passing it to an environment variable in the first step and referencing that in the email step, and passing it to an HTML file in the first step and referencing that, all of which failed.
My sanitized Github action code:
on:
workflow_dispatch:
inputs:
site_name:
description: 'Site hostname'
required: true
default: 'dev.llamasrkewl.com'
type: text
jobs:
deploy_new_website:
runs-on: self-hosted
steps:
- run: |
site_name="${{ github.event.inputs.site_name }}"
ansible-playbook playbook1.yml -e "site_name=$site_name"
ansible-playbook playbook2.yml -e "site_name=$site_name"
ansible-playbook playbook3.yml -e "site_name=$site_name"
id: site_deployment
shell: bash
- name: Send mail
if: always()
uses: dawidd6/action-send-mail@v3
with:
server_address: smtp_server.mydomain.com
subject: ${{ github.repository }} deployment status ${{ job.status }}
to: me.mydomain.com
from: [email protected]
body: [??? $site_name? ${{ github.event.inputs.site_name }}? other?] has status of ${{ job.status }}
I will personally send an actual live llama to anyone who can help me solve this (optional).
CodePudding user response:
Minor issue that is not easy to figure out: change your input type from text
to string
.
on:
workflow_dispatch:
inputs:
site_name:
description: 'Site hostname'
required: true
default: 'dev.llamasrkewl.com'
type: string
The only valid values for type are boolean, number, or string