Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adicionando o playbook para centos #2

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions install_k8s_centos/hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[k8s-master]


[k8s-workers]


[k8s-workers:vars]
K8S_MASTER_NODE_IP=
K8S_API_SECURE_PORT=6443
25 changes: 25 additions & 0 deletions install_k8s_centos/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
- hosts: all
become: yes
user: centos
gather_facts: no
pre_tasks:
- name: 'atualizando repo'
raw: yum update -y

- name: 'instalando o python'
raw: yum install python2 python -y

roles:
- { role: install-k8s, tags: ["install_k8s_role"]}

- hosts: k8s-master
become: yes
user: centos
roles:
- { role: create-cluster, tags: ["create_cluster_role"]}

- hosts: k8s-workers
become: yes
user: centos
roles:
- { role: join-workers, tags: ["join_workers_role"]}
38 changes: 38 additions & 0 deletions install_k8s_centos/roles/create-cluster/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Role Name
=========

A brief description of the role goes here.

Requirements
------------

Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.

Role Variables
--------------

A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.

Dependencies
------------

A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.

Example Playbook
----------------

Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:

- hosts: servers
roles:
- { role: username.rolename, x: 42 }

License
-------

BSD

Author Information
------------------

An optional section for the role authors to include contact information, or a website (HTML is not allowed).
2 changes: 2 additions & 0 deletions install_k8s_centos/roles/create-cluster/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# defaults file for create-cluster
2 changes: 2 additions & 0 deletions install_k8s_centos/roles/create-cluster/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# handlers file for create-cluster
53 changes: 53 additions & 0 deletions install_k8s_centos/roles/create-cluster/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
galaxy_info:
author: your name
description: your description
company: your company (optional)

# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker

# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)

min_ansible_version: 2.4

# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:

#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99

galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.

dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.

37 changes: 37 additions & 0 deletions install_k8s_centos/roles/create-cluster/tasks/init-cluster.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
- name: Reset Cluster
command:
kubeadm reset --force
register: kubeadmin_init
- name: Initialize Kubernetes master with kubeadm init.
command:
kubeadm init
register: kubeadmin_init
- name: Ensure .kube directory exists.
file:
path: ~/.kube
state: directory
- name: Symlink the kubectl admin.conf to ~/.kube/conf.
file:
src: /etc/kubernetes/admin.conf
dest: ~/.kube/config
state: link
- name: Configure weavenet networking.
shell: kubectl apply -f {{ default_kubernetes_cni_weavenet_manifestUrl }}
register: weavenet_result
- name: "Cluster token"
shell: kubeadm token list | cut -d ' ' -f1 | sed -n '2p'
register: K8S_TOKEN
- name: "CA Hash"
shell: openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'
register: K8S_MASTER_CA_HASH
- name: "Add K8S Token and Hash to dummy host"
add_host:
name: "K8S_TOKEN_HOLDER"
token: "{{ K8S_TOKEN.stdout }}"
hash: "{{ K8S_MASTER_CA_HASH.stdout }}"
- name: ''
debug:
msg: "[Master] K8S_TOKEN_HOLDER K8S token is {{ hostvars['K8S_TOKEN_HOLDER']['token'] }}"
- name: ''
debug:
msg: "[Master] K8S_TOKEN_HOLDER K8S Hash is {{ hostvars['K8S_TOKEN_HOLDER']['hash'] }}"
3 changes: 3 additions & 0 deletions install_k8s_centos/roles/create-cluster/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
# tasks file for create-cluster
- include: init-cluster.yml
2 changes: 2 additions & 0 deletions install_k8s_centos/roles/create-cluster/tests/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
localhost

5 changes: 5 additions & 0 deletions install_k8s_centos/roles/create-cluster/tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- create-cluster
3 changes: 3 additions & 0 deletions install_k8s_centos/roles/create-cluster/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
# vars file for create-cluster
default_kubernetes_cni_weavenet_manifestUrl: "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
38 changes: 38 additions & 0 deletions install_k8s_centos/roles/install-k8s/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Role Name
=========

A brief description of the role goes here.

Requirements
------------

Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.

Role Variables
--------------

A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.

Dependencies
------------

A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.

Example Playbook
----------------

Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:

- hosts: servers
roles:
- { role: username.rolename, x: 42 }

License
-------

BSD

Author Information
------------------

An optional section for the role authors to include contact information, or a website (HTML is not allowed).
2 changes: 2 additions & 0 deletions install_k8s_centos/roles/install-k8s/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# defaults file for install-k8s
2 changes: 2 additions & 0 deletions install_k8s_centos/roles/install-k8s/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# handlers file for install-k8s
53 changes: 53 additions & 0 deletions install_k8s_centos/roles/install-k8s/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
galaxy_info:
author: your name
description: your description
company: your company (optional)

# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker

# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)

min_ansible_version: 2.4

# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:

#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99

galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.

dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.

68 changes: 68 additions & 0 deletions install_k8s_centos/roles/install-k8s/tasks/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
- name: desativando o SeLinux
selinux:
state: disabled

- name: desativando o Firewalld
yum:
name: firewalld
state: removed

- name: instalando o iptables
yum:
name: iptables
state: present

- name: desativando o swap
shell: swapoff -a

- name: removendo o swap
replace:
path: /etc/fstab
regexp: '^([^#].*?\sswap\s+sw\s+.*)$'
replace: '# \1'

- name: Permitindo o Forward no Centos
shell: echo 1 > /proc/sys/net/ipv4/ip_forward

- name: gravando o forward persistente a reinicios
sysctl:
name: net.ipv4.ip_forward
reload: yes
state: present
value: '1'

- name: Adicionando o Repositorio do Docker
shell: curl -fSsl https://download.docker.com/linux/centos/docker-ce.repo > /etc/yum.repos.d/docker-ce.repo

- name: Adicionando o repo do kubernetes no YUM
yum_repository:
name: kubernetes
file: kubernetes
description: kubernetes
baseurl: https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
gpgcheck: yes
repo_gpgcheck: yes
gpgkey:
- https://packages.cloud.google.com/yum/doc/yum-key.gpg
- https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
enabled: yes
state: present

- name: Instalando o Docker
yum:
name: docker-ce
state: latest

- name: iniciando o servico do Docker
systemd:
name: docker
state: started

- name: Install k8s packages
yum:
name: "{{ packages }}"
vars:
packages:
- kubelet
- kubeadm
- kubectl
3 changes: 3 additions & 0 deletions install_k8s_centos/roles/install-k8s/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
# tasks file for install-k8s
- include: install.yml
2 changes: 2 additions & 0 deletions install_k8s_centos/roles/install-k8s/tests/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
localhost

5 changes: 5 additions & 0 deletions install_k8s_centos/roles/install-k8s/tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- install-k8s
2 changes: 2 additions & 0 deletions install_k8s_centos/roles/install-k8s/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# vars file for install-k8s
Loading