Skip to content

Commit 1d34a95

Browse files
authored
Merge pull request #17 from sap-linuxlab/dev
feat: evergreen software-update replace filenames
2 parents 81023fd + def9e11 commit 1d34a95

File tree

2 files changed

+69
-8
lines changed

2 files changed

+69
-8
lines changed

.github/workflows/terraform_ansible_software_availability.yml

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,24 @@ jobs:
2727
terraform_module_ansible: [ansible_sap_ecc_hana_system_copy_hdb,ansible_sap_hana_install,ansible_sap_s4hana_install_maintplan,ansible_sap_s4hana_system_copy_hdb]
2828
steps:
2929
- name: Checkout
30-
uses: actions/checkout@v2
30+
uses: actions/checkout@v3.0.2
31+
with:
32+
path: gh_repo
3133
- name: Ansible setup
3234
id: local_setup
3335
run: |
3436
python --version
3537
python -m pip install ansible-core requests beautifulsoup4 lxml
3638
ansible --version
37-
ansible-galaxy collection install git+https://github.com/sap-linuxlab/community.sap_launchpad.git,main
39+
ansible-galaxy collection install git+https://github.com/sap-linuxlab/community.sap_launchpad.git,main -p ./ansible_collections
3840
- name: Terraform Module for Ansible - check software
3941
id: identify_software_list
4042
env:
4143
sap_user_id: ${{ secrets.SAP_USER_ID }}
4244
sap_user_id_password: ${{ secrets.SAP_USER_ID_PASSWORD }}
4345
run: |
44-
cd "./all/${{ matrix.terraform_module_ansible }}"
46+
export ANSIBLE_COLLECTIONS_PATH="$PWD/ansible_collections"
47+
cd "./gh_repo/all/${{ matrix.terraform_module_ansible }}"
4548
# Extract from softwarecenter_search_list_.* until first empty line, then remove yaml formatting and sort for unique
4649
export software_list=$(cat create_ansible_extravars.tf | awk '!NF{f=0} /^.*softwarecenter_search_list.*/{f=1} f{print}' | awk '!/.*softwarecenter_search_list.*/' | awk '{sub(/#.*/,""); print}' | awk '{sub(/ .*- '\''/,""); print}' | tr -d "'" | sort | uniq)
4750
export errors_list=""
@@ -57,13 +60,71 @@ jobs:
5760
continue
5861
fi
5962
done
63+
cd ../../../
6064
if [ -z "$errors_list" ]
6165
then
6266
exit 0
6367
else
64-
echo "### ERRORS indentified ####"
65-
echo "Terraform Templates for SAP require updating,"
68+
echo "### ERRORS identified ####"
69+
echo "Terraform Modules for SAP require updating,"
6670
echo "as the following SAP Software are no longer available:"
6771
echo "$errors_list" | tr " " "\n"
68-
exit 1
72+
cd ./ansible_collections/community/sap_launchpad/plugins
73+
touch python_module_fuzzy_call_script.py
74+
echo '#!/usr/bin/env python3' >> python_module_fuzzy_call_script.py
75+
echo 'import sys' >> python_module_fuzzy_call_script.py
76+
echo 'search_file=sys.argv[1]' >> python_module_fuzzy_call_script.py
77+
echo 'from module_utils.sap_launchpad_software_center_download_search_fuzzy import *' >> python_module_fuzzy_call_script.py
78+
echo "username='$sap_user_id'" >> python_module_fuzzy_call_script.py
79+
echo "password='$sap_user_id_password'" >> python_module_fuzzy_call_script.py
80+
echo 'sap_sso_login(username, password)' >> python_module_fuzzy_call_script.py
81+
echo 'query_result = search_software_fuzzy(search_file)' >> python_module_fuzzy_call_script.py
82+
echo 'if len(query_result) >= 2:' >> python_module_fuzzy_call_script.py
83+
echo " if 'IMDB_CLIENT20' in query_result[0]['Title']:" >> python_module_fuzzy_call_script.py
84+
echo " print(query_result[-1]['Title'])" >> python_module_fuzzy_call_script.py
85+
echo " elif '70SWPM' in query_result[0]['Title']:" >> python_module_fuzzy_call_script.py
86+
echo " print(query_result[-1]['Title'])" >> python_module_fuzzy_call_script.py
87+
echo " else:" >> python_module_fuzzy_call_script.py
88+
echo ' for item in query_result:' >> python_module_fuzzy_call_script.py
89+
echo ' print("ERROR. More than 1 result, manual intervention required.")' >> python_module_fuzzy_call_script.py
90+
echo " print('Identified ' + item['Description'] + ', ' + item['Infotype'] + ': ' + item['Title'])" >> python_module_fuzzy_call_script.py
91+
echo 'else:' >> python_module_fuzzy_call_script.py
92+
echo " print(query_result[0]['Title'])" >> python_module_fuzzy_call_script.py
93+
export exit1_check=0
94+
cd ../../../../
95+
for filename in $errors_list
96+
do
97+
filename_noext="${filename%.*}"
98+
filename_id_only="${filename_noext##*-}"
99+
cd ./ansible_collections/community/sap_launchpad/plugins
100+
search_file=$(python ./python_module_fuzzy_call_script.py $filename_id_only)
101+
cd ../../../../
102+
if [[ "$search_file" == *"ERROR"* ]]; then
103+
echo -e $search_file
104+
printf $search_file
105+
exit1_check=1
106+
else
107+
echo "Perform recursive sed for $filename change to $search_file"
108+
cd "./gh_repo/all/${{ matrix.terraform_module_ansible }}"
109+
find . -type f -not -path '*/\.*' -exec sed -i "s/$filename/$search_file/g" {} \;
110+
cd ../../../
111+
fi
112+
done
113+
if [[ "$exit1_check" -eq 1 ]]; then
114+
exit 1
115+
fi
116+
fi
117+
- name: Commit to main branch
118+
id: git_commit_auto
119+
run: |
120+
cd ./gh_repo
121+
if [[ $(git status --porcelain) ]]; then
122+
git config user.name github-actions
123+
git config user.email github-actions@github.com
124+
git add .
125+
git status
126+
git commit -m "software-update: replace with new filenames $(date +%F_%H-%M)"
127+
git push
128+
else
129+
exit 0
69130
fi

all/ansible_sap_ecc_hana_system_copy_hdb/create_ansible_extravars.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ softwarecenter_search_list_ecc_syscopy_x86_64:
2020
- 'IMDB_LCAPPS_2059_0-20010426.SAR'
2121
- 'IMDB_AFL20_059_0-80001894.SAR'
2222
- 'VCH202000_2059_0-80005463.SAR'
23-
- 'SWPM10SP35_5-20009701.SAR'
23+
- 'SWPM10SP35_6-20009701.SAR'
2424
- 'igsexe_12-80003187.sar' # IGS 7.53
2525
- 'igshelper_17-10010245.sar'
2626
- 'SAPEXE_800-80002573.SAR' # Kernel Part I (753)
@@ -34,7 +34,7 @@ softwarecenter_search_list_ecc_syscopy_ppc64le:
3434
- 'IMDB_LCAPPS_2059_0-80002183.SAR'
3535
- 'IMDB_AFL20_059_0-80002045.SAR'
3636
- 'VCH202000_2059_0-80005464.SAR'
37-
- 'SWPM10SP35_5-70002492.SAR'
37+
- 'SWPM10SP35_6-70002492.SAR'
3838
- 'igsexe_12-80003246.sar' # IGS 7.53
3939
- 'igshelper_17-10010245.sar'
4040
- 'SAPEXE_800-80002630.SAR' # Kernel Part I (753)

0 commit comments

Comments
 (0)