Skip to content

Commit

Permalink
Use YQ for inventory generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Daemonslayer2048 committed Jan 9, 2025
1 parent 3f9263a commit e3623ad
Showing 1 changed file with 35 additions and 47 deletions.
82 changes: 35 additions & 47 deletions .github/workflows/reusable_integration_testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,46 +82,34 @@ jobs:
if: steps.plan.outcome == 'failure'
run: exit 1

# - name: Terraform Apply
# run: |
# cd testing/
# terraform apply -var "GITHUB_RUN_ID=$GITHUB_RUN_ID" -var "os=${{ inputs.os }}" -auto-approve
# env:
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# AWS_DEFAULT_REGION: us-gov-west-1

# - name: Create inventory
# run: |
# cp -R inventory/${{ inputs.os }}
- name: Terraform Apply
run: |
cd testing/
terraform apply -var "GITHUB_RUN_ID=$GITHUB_RUN_ID" -var "os=${{ inputs.os }}" -auto-approve
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: us-gov-west-1

# - name: Create inventory hosts.yml
# run: |
# touch hosts.yml
# echo "rke2_cluster:" > hosts.yml
# echo " children:" >> hosts.yml
# echo " rke2_servers:" >> hosts.yml
# echo " hosts:" >> hosts.yml
# echo " $(aws ec2 describe-instances --filters "Name=instance-state-name,Values=running" "Name=tag:Owner,Values=rke2-ansible-github-actions" "Name=tag:NodeType,Values=Server" "Name=tag:github_run,Values=$GITHUB_RUN_ID" --query "Reservations[*].Instances[*].PublicIpAddress" --output text | head -1):" >> hosts.yml
# echo " rke2_agents:" >> hosts.yml
# echo " hosts:" >> hosts.yml
# echo " $(aws ec2 describe-instances --filters "Name=instance-state-name,Values=running" "Name=tag:Owner,Values=rke2-ansible-github-actions" "Name=tag:NodeType,Values=Agent" "Name=tag:github_run,Values=$GITHUB_RUN_ID" --query "Reservations[*].Instances[*].PublicIpAddress" --output text | head -1):" >> hosts.yml
# echo "all:" >> hosts.yml
# echo " vars:" >> hosts.yml
# echo " rke2_kubernetes_api_server_host: $(aws ec2 describe-instances --filters "Name=instance-state-name,Values=running" "Name=tag:Owner,Values=rke2-ansible-github-actions" "Name=tag:NodeType,Values=Server" "Name=tag:github_run,Values=$GITHUB_RUN_ID" --query "Reservations[*].Instances[*].PrivateIpAddress" --output text | head -1)" >> hosts.yml
# echo "" >> ansible.cfg
# echo "" >> ansible.cfg
# echo "remote_user=centos" >> ansible.cfg
# echo "private_key_file=.key" >> ansible.cfg
# env:
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# AWS_DEFAULT_REGION: us-gov-west-1
- name: Create inventory
run: |
mkdir ./${{ inputs.os }}
export RKE2_SERVER=$(aws ec2 describe-instances --filters "Name=instance-state-name,Values=running" "Name=tag:Owner,Values=rke2-ansible-github-actions" "Name=tag:NodeType,Values=Server" "Name=tag:github_run,Values=$GITHUB_RUN_ID" --query "Reservations[*].Instances[*].PublicIpAddress" --output text | head -1)
export RKE2_AGENT=$(aws ec2 describe-instances --filters "Name=instance-state-name,Values=running" "Name=tag:Owner,Values=rke2-ansible-github-actions" "Name=tag:NodeType,Values=Agent" "Name=tag:github_run,Values=$GITHUB_RUN_ID" --query "Reservations[*].Instances[*].PublicIpAddress" --output text | head -1)
yq --null-input '(.rke2_cluster.children.rke2_servers.hosts.master-01.ansible_host = strenv(RKE2_SERVER)' > ./${{ inputs.os }}/hosts.yml
yq -i '(.all.vars.rke2_kubernetes_api_server_host = strenv(RKE2_SERVER)' ./${{ inputs.os }}/hosts.yml
yq -i '(.rke2_cluster.children.rke2_agents.hosts.worker-01.ansible_host = strenv(RKE2_SERVER)' ./${{ inputs.os }}/hosts.yml
echo "remote_user=centos" >> ansible.cfg
echo "private_key_file=.key" >> ansible.cfg
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: us-gov-west-1

# - name: Check hosts.yml and ansible.cfg
# run: |
# cat hosts.yml
# cat ansible.cfg
- name: Check hosts.yml and ansible.cfg
run: |
cat hosts.yml
cat ansible.cfg
# - name: Run playbook
# run: |
Expand Down Expand Up @@ -182,13 +170,13 @@ jobs:
# run: |
# ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i inventory/rocky8/hosts.yml -u centos -vvv --tags "troubleshooting" --private-key .key testing.yml

# - name: Delete Stack
# if: ${{ always() }}
# run: |
# cd testing/
# terraform destroy -var "GITHUB_RUN_ID=$GITHUB_RUN_ID" -auto-approve
# env:
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# AWS_DEFAULT_REGION: us-gov-west-1
- name: Delete Stack
if: ${{ always() }}
run: |
cd testing/
terraform destroy -var "GITHUB_RUN_ID=$GITHUB_RUN_ID" -auto-approve
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: us-gov-west-1

0 comments on commit e3623ad

Please sign in to comment.