Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yogesh174/26b7673f9d9222aac718e524f00b26d1 to your computer and use it in GitHub Desktop.
Save yogesh174/26b7673f9d9222aac718e524f00b26d1 to your computer and use it in GitHub Desktop.
Multi-cloud K8s cluster with Terraform and Ansible
- hosts: aws-k8s-master
become: yes
gather_facts: no
tasks:
- name: "Create token command for worker nodes"
shell: "kubeadm token create --print-join-command"
register: join_cmd
args:
warn: false
- hosts: azure-k8s-nodes
become: yes
tasks:
- name: "Add Kubernetes apt-key"
apt_key:
url: "https://packages.cloud.google.com/apt/doc/apt-key.gpg"
state: "present"
- name: "Add Kubernetes apt repo"
apt_repository:
repo: "deb http://apt.kubernetes.io/ kubernetes-xenial main"
state: "present"
filename: "kubernetes"
- name: "Install APT Transport HTTPS"
apt:
name: "apt-transport-https"
state: "present"
update_cache: true
- name: "Docker Installation"
apt:
name: "docker.io"
state: "present"
- name: "Copy docker daemon file"
copy:
src: "../daemon.json"
dest: "/etc/docker/"
- name: "Restart docker service"
service:
name: "docker"
state: "restarted"
- name: "Install kubelet"
apt:
name: "kubelet"
state: "present"
- name: "Install kubeadm"
apt:
name: "kubeadm"
state: "present"
- name: "Join with master"
shell: "{{ hostvars[groups['aws-k8s-master'][0]]['join_cmd']['stdout'] }}"
ignore_errors: yes
- name: "Create terraform env file"
file:
path: "/etc/profile.d/terraform.sh"
state: "touch"
owner: "root"
group: "root"
mode: "0644"
- name: "Add IS_CONFIGURED env var"
lineinfile:
path: "/etc/profile.d/terraform.sh"
insertafter: 'EOF'
line: "export IS_CONFIGURED=1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment