Skip to content

Commit f913800

Browse files
authored
Fix/enhance increse-node-size github action
2 parents 504a95c + 22c002d commit f913800

2 files changed

Lines changed: 101 additions & 54 deletions

File tree

.github/workflows/node-increase-disk.yml

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,28 @@ on:
1818
description: "The amount of diskspace to add (GB)"
1919
default: "50"
2020
required: true
21+
disk:
22+
description: "The disk to increase using growpart (e.g., /dev/xvda)"
23+
default: "/dev/xvda"
24+
required: true
25+
partition_number:
26+
description: "The partition number to extend using growpart (e.g., 1)"
27+
default: "1"
28+
required: true
29+
partition_device:
30+
description: "The partition device to extend using resize2fs (e.g., /dev/xvda1)"
31+
default: "/dev/xvda1"
32+
required: true
2133

2234

2335
jobs:
2436
increase-disk:
2537
environment: ${{inputs.network}}
2638
runs-on: ubuntu-latest
2739
steps:
40+
- name: Install jq
41+
run: sudo apt-get install -y jq
42+
2843
- name: Checkout
2944
uses: actions/checkout@v4
3045

@@ -39,14 +54,31 @@ jobs:
3954
aws_secret_access_key: ${{ secrets.AWS_SECRET_KEY }}
4055
aws_region: ${{vars.S3_REGION}}
4156

42-
- name: Run playbook
43-
uses: arillso/action.playbook@master
57+
- uses: actions/setup-python@v5
4458
with:
45-
# Required, playbook filepath
46-
playbook: ./scripts/ansible/aws/ec2-modify-volume-size.yml
47-
inventory: ./ansible-hosts
48-
galaxy_file: ./scripts/ansible/aws/requirements.yml
49-
extra_vars: "aws_region=${{github.event.inputs.aws_region}} instance_id=${{inputs.instance_id}} aws_secret_key=${{secrets.AWS_SECRET_KEY}} aws_access_key_id=${{secrets.AWS_ACCESS_KEY_ID}} volume_size=${{github.event.inputs.disk_size}} ansible_python_interpreter='/usr/bin/python3'"
59+
python-version: '3.11'
60+
61+
- name: Install Ansible + deps
62+
run: |
63+
python -m pip install --upgrade pip
64+
pip install "ansible-core>=2.16" boto3 botocore packaging
65+
66+
- name: Galaxy install
67+
run: ansible-galaxy install -r ./scripts/ansible/aws/requirements.yml
68+
69+
- name: Run playbook
70+
env:
71+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
72+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_KEY }}
73+
run: |
74+
ansible-playbook \
75+
-i ./ansible-hosts \
76+
--extra-vars "aws_region=${{github.event.inputs.aws_region}} instance_id=${{inputs.instance_id}} aws_secret_key=${{secrets.AWS_SECRET_KEY}} aws_access_key_id=${{secrets.AWS_ACCESS_KEY_ID}} volume_size=${{github.event.inputs.disk_size}} ansible_python_interpreter='/usr/bin/python3'" \
77+
./scripts/ansible/aws/ec2-modify-volume-size.yml
78+
79+
- name: Wait for AWS to finish provisioning the disk
80+
run: sleep 30m
81+
shell: bash
5082

5183
- name: Extend file system
5284
id: extend-file-system
@@ -59,14 +91,29 @@ jobs:
5991
[{"Key":"InstanceIds","Values":["${{ inputs.instance_id }}"]}]
6092
document-name: AWS-RunShellScript
6193
parameters: |
62-
{"commands":["sudo growpart /dev/nvme0n1 1", "sudo resize2fs /dev/nvme0n1p1"]}
94+
{
95+
"commands":[
96+
"sudo growpart ${{ inputs.disk }} ${{ inputs.partition_number }}",
97+
"sudo resize2fs ${{ inputs.partition_device }}"
98+
]
99+
}
63100
64-
- name: Check SSM output
65-
if: steps.extend-file-system.outcome == 'success'
101+
- name: Get SSM output
102+
if: always()
103+
id: get-ssm-output
66104
env:
67105
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
68106
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_KEY }}
69107
AWS_DEFAULT_REGION: ${{ inputs.aws_region }}
70108
run: |
71-
aws ssm list-command-invocations --command-id "${{ steps.extend-file-system.outputs.command-id }}" --details
109+
COMMAND_OUTPUT=$(aws ssm list-command-invocations --command-id ${{ steps.extend-file-system.outputs.command-id }} --details | jq -c .)
110+
echo "COMMAND_OUTPUT=$COMMAND_OUTPUT" >> $GITHUB_ENV
111+
112+
- name: Check SSM output
113+
if: steps.get-ssm-output.outcome == 'success' && !contains(env.COMMAND_OUTPUT, 'Status:Success')
114+
run: |
115+
echo "Error detected trying to extend the partition."
116+
echo ${{env.COMMAND_OUTPUT}}
117+
exit 1
118+
72119

scripts/ansible/aws/ec2-modify-volume-size.yml

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,49 @@
66
volume_type_default: "{{ volume_type | default('io1') }}"
77

88
pre_tasks:
9-
- name: Install dependencies
10-
pip: name={{ item }}
11-
with_items:
12-
- boto3
13-
- botocore
9+
- name: Install dependencies
10+
pip: name={{ item }}
11+
with_items:
12+
- boto3
13+
- botocore
1414

1515
tasks:
16-
17-
- name: Get EC2 instance state
18-
amazon.aws.ec2_instance:
19-
aws_access_key_id: "{{ aws_access_key_id }}"
20-
aws_secret_access_key: "{{ aws_secret_key }}"
21-
region: "{{ aws_region }}"
22-
instance_ids: [ "{{instance_id}}" ]
23-
register: instances
24-
25-
- name: EC2 instance info
26-
ansible.builtin.debug:
27-
msg: Instance ID {{ instances['instances'][0].instance_id }}, root volume {{ instances['instances'][0].block_device_mappings[0].ebs }}
28-
29-
- name: Get current volume info
30-
amazon.aws.ec2_vol:
31-
aws_access_key_id: "{{ aws_access_key_id }}"
32-
aws_secret_access_key: "{{ aws_secret_key }}"
33-
region: "{{ aws_region }}"
34-
instance: "{{ instance_id }}"
35-
id: "{{ instances['instances'][0].block_device_mappings[0].ebs.volume_id }}"
36-
modify_volume: false
37-
register: volume_info
38-
39-
- name: EC2 volume info
40-
ansible.builtin.debug:
41-
msg: Volume ID {{ instances['instances'][0].block_device_mappings[0].ebs.volume_id }}, Old size {{ volume_info.volume.size }}, New size {{ volume_info.volume.size|int + volume_size|int }}
42-
43-
- name: Modify the volume
44-
amazon.aws.ec2_vol:
45-
aws_access_key_id: "{{ aws_access_key_id }}"
46-
aws_secret_access_key: "{{ aws_secret_key }}"
47-
region: "{{ aws_region }}"
48-
instance: "{{ instance_id }}"
49-
id: "{{ instances['instances'][0].block_device_mappings[0].ebs.volume_id }}"
50-
volume_size: "{{ volume_info.volume.size|int + volume_size|int }}"
51-
volume_type: "{{ volume_type_default }}"
52-
iops: "{{ iops | default(1300) if volume_type_default is regex('^io*') else omit }}"
53-
modify_volume: true
16+
- name: Get EC2 instance state
17+
amazon.aws.ec2_instance:
18+
aws_access_key_id: "{{ aws_access_key_id }}"
19+
aws_secret_access_key: "{{ aws_secret_key }}"
20+
region: "{{ aws_region }}"
21+
instance_ids: [ "{{instance_id}}" ]
22+
register: instances
23+
24+
- name: EC2 instance info
25+
ansible.builtin.debug:
26+
msg: Instance ID {{ instances['instances'][0].instance_id }}, root volume {{ instances['instances'][0].block_device_mappings[0].ebs }}
27+
28+
- name: Get current volume info
29+
amazon.aws.ec2_vol:
30+
aws_access_key_id: "{{ aws_access_key_id }}"
31+
aws_secret_access_key: "{{ aws_secret_key }}"
32+
region: "{{ aws_region }}"
33+
instance: "{{ instance_id }}"
34+
id: "{{ instances['instances'][0].block_device_mappings[0].ebs.volume_id }}"
35+
modify_volume: false
36+
register: volume_info
37+
38+
- name: EC2 volume info
39+
ansible.builtin.debug:
40+
msg: Volume ID {{ instances['instances'][0].block_device_mappings[0].ebs.volume_id }}, Old size {{ volume_info.volume.size }}, New size {{ volume_info.volume.size|int + volume_size|int }}
41+
42+
- name: Modify the volume
43+
amazon.aws.ec2_vol:
44+
aws_access_key_id: "{{ aws_access_key_id }}"
45+
aws_secret_access_key: "{{ aws_secret_key }}"
46+
region: "{{ aws_region }}"
47+
instance: "{{ instance_id }}"
48+
id: "{{ instances['instances'][0].block_device_mappings[0].ebs.volume_id }}"
49+
volume_size: "{{ volume_info.volume.size|int + volume_size|int }}"
50+
volume_type: "{{ volume_type_default }}"
51+
iops: "{{ iops | default(1300) if volume_type_default is regex('^io*') else omit }}"
52+
modify_volume: true
53+
5454

0 commit comments

Comments
 (0)