Skip to content

Commit

Permalink
Merge pull request #132 from oomichi/add-azure-ansible
Browse files Browse the repository at this point in the history
Add k8s deployment with Ansible
  • Loading branch information
oomichi authored Dec 16, 2023
2 parents 13403b4 + 5b530d0 commit ca73d3b
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
ci/03_ansible/hosts
deployments/kubespray/container-images/
deployments/ansible/venv-ansible
deployments/ansible/aks.yaml
20 changes: 20 additions & 0 deletions deployments/ansible/aks.yaml.template
Original file line number Diff line number Diff line change
@@ -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
52 changes: 52 additions & 0 deletions deployments/ansible/requirements-azure.txt
Original file line number Diff line number Diff line change
@@ -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
40 changes: 40 additions & 0 deletions deployments/ansible/run-ansible.sh
Original file line number Diff line number Diff line change
@@ -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/<subscription id>"
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
2 changes: 1 addition & 1 deletion tests/check_typo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ca73d3b

Please sign in to comment.