From 5b530d0099f4a17a2e4e4e09ed229ce4b61082fb Mon Sep 17 00:00:00 2001 From: Kenichi Omichi Date: Sat, 16 Dec 2023 05:33:17 +0000 Subject: [PATCH] Add ansible --- .gitignore | 2 + deployments/ansible/aks.yaml.template | 20 +++++++++ deployments/ansible/requirements-azure.txt | 52 ++++++++++++++++++++++ deployments/ansible/run-ansible.sh | 40 +++++++++++++++++ tests/check_typo.sh | 2 +- 5 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 deployments/ansible/aks.yaml.template create mode 100644 deployments/ansible/requirements-azure.txt create mode 100755 deployments/ansible/run-ansible.sh diff --git a/.gitignore b/.gitignore index 950c8ec..18bf34c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ ci/03_ansible/hosts deployments/kubespray/container-images/ +deployments/ansible/venv-ansible +deployments/ansible/aks.yaml diff --git a/deployments/ansible/aks.yaml.template b/deployments/ansible/aks.yaml.template new file mode 100644 index 0000000..1582d13 --- /dev/null +++ b/deployments/ansible/aks.yaml.template @@ -0,0 +1,20 @@ +- name: Create Azure Kubernetes Service + hosts: localhost + connection: local + tasks: + - name: Create resource group + azure.azcollection.azure_rm_resourcegroup: + name: ${AKS_RESOURCE_GROUP} + location: japaneast + - name: Create AKS Cluster + azure.azcollection.azure_rm_aks: + name: ${AKS_NAME} + kubernetes_version: 1.27.7 + location: japaneast + resource_group: ${AKS_RESOURCE_GROUP} + dns_prefix: akstest + agent_pool_profiles: + - name: agentpool1 + mode: System + count: 1 + vm_size: Standard_D2_v2 diff --git a/deployments/ansible/requirements-azure.txt b/deployments/ansible/requirements-azure.txt new file mode 100644 index 0000000..5fc0064 --- /dev/null +++ b/deployments/ansible/requirements-azure.txt @@ -0,0 +1,52 @@ +packaging +requests[security] +xmltodict +msgraph-sdk==1.0.0 +azure-cli-core==2.34.0 +azure-common==1.1.11 +azure-identity==1.14.0 +azure-mgmt-authorization==2.0.0 +azure-mgmt-apimanagement==3.0.0 +azure-mgmt-batch==16.2.0 +azure-mgmt-cdn==11.0.0 +azure-mgmt-compute==26.1.0 +azure-mgmt-containerinstance==9.0.0 +azure-mgmt-core==1.3.0 +azure-mgmt-containerregistry==9.1.0 +azure-containerregistry==1.1.0 +azure-mgmt-containerservice==20.0.0 +azure-mgmt-datalake-store==1.0.0 +azure-mgmt-datafactory==2.0.0 +azure-mgmt-dns==8.0.0 +azure-mgmt-marketplaceordering==1.1.0 +azure-mgmt-monitor==3.0.0 +azure-mgmt-managedservices==6.0.0 +azure-mgmt-managementgroups==1.0.0 +azure-mgmt-network==19.1.0 +azure-mgmt-nspkg==2.0.0 +azure-mgmt-privatedns==1.0.0 +azure-mgmt-redis==13.0.0 +azure-mgmt-resource==21.1.0 +azure-mgmt-rdbms==10.0.0 +azure-mgmt-search==8.0.0 +azure-mgmt-servicebus==7.1.0 +azure-mgmt-sql==3.0.1 +azure-mgmt-storage==19.0.0 +azure-mgmt-trafficmanager==1.0.0b1 +azure-mgmt-web==6.1.0 +azure-nspkg==2.0.0 +azure-storage-blob==12.11.0 +azure-core==1.28.0 +azure-keyvault==4.2.0 +azure-mgmt-keyvault==10.0.0 +azure-mgmt-cosmosdb==6.4.0 +azure-mgmt-hdinsight==9.0.0 +azure-mgmt-devtestlabs==9.0.0 +azure-mgmt-loganalytics==12.0.0 +azure-mgmt-automation==1.0.0 +azure-mgmt-iothub==2.2.0 +azure-iot-hub==2.6.1 +azure-mgmt-recoveryservices==2.0.0 +azure-mgmt-recoveryservicesbackup==3.0.0 +azure-mgmt-notificationhubs==7.0.0 +azure-mgmt-eventhub==10.1.0 diff --git a/deployments/ansible/run-ansible.sh b/deployments/ansible/run-ansible.sh new file mode 100755 index 0000000..e473ad4 --- /dev/null +++ b/deployments/ansible/run-ansible.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +cd $(dirname $0) + +export AKS_RESOURCE_GROUP=${AKS_RESOURCE_GROUP:-"aks_rg"} +export AKS_NAME=${AKS_NAME:-"akstest"} + +if [ "${AZURE_SUBSCRIPTION_ID}" == "" ] || [ "${AZURE_CLIENT_ID}" == "" ] || [ "${AZURE_SECRET}" == "" ] || [ "${AZURE_TENANT}" == "" ]; then + echo "Environment variables AZURE_SUBSCRIPTION_ID, AZURE_CLIENT_ID, AZURE_SECRET and AZURE_TENANT should be specified." + echo "To create a service principal which contains the variables, run the following steps:" + echo " $ curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash" + echo " $ az login" + echo " $ az ad sp create-for-rbac --name ansible --role Contributor --scopes /subscriptions/" + exit 1 +fi + +if [ ! -d ./venv-ansible ]; then + set -e + sudo apt update + sudo apt -y install python3-pip python3-venv + python3 -m venv ./venv-ansible + source ./venv-ansible/bin/activate + + pip install ansible + ansible --version + # NOTE: requirements-azure.txt is downloaded by the following command. + # If necessary, please update it by doing again. + # curl -O https://raw.githubusercontent.com/ansible-collections/azure/dev/requirements-azure.txt + pip install -r requirements-azure.txt + ansible-galaxy collection install azure.azcollection + set +e +else + source ./venv-ansible/bin/activate +fi + +set -e + +envsubst < ./aks.yaml.template > ./aks.yaml +ansible-playbook ./aks.yaml +az aks get-credentials --resource-group ${AKS_RESOURCE_GROUP} --name ${AKS_NAME} --admin diff --git a/tests/check_typo.sh b/tests/check_typo.sh index cf80d5e..c6617b8 100755 --- a/tests/check_typo.sh +++ b/tests/check_typo.sh @@ -9,4 +9,4 @@ set -e wget https://github.com/client9/misspell/releases/download/v0.3.4/misspell_0.3.4_linux_64bit.tar.gz tar -zxvf ./misspell_0.3.4_linux_64bit.tar.gz chmod 755 ./misspell -git ls-files | xargs ./misspell -error +git ls-files | grep -v requirements-azure.txt | xargs ./misspell -error