---
- name: 使用 hostname 模块设置主机名
  hostname:
    name: "{{ inventory_hostname }}"

- name: 配置国内YUM源
  yum_repository:
    name: aliyun-base
    description: Aliyun CentOS $releasever - Base
    baseurl: "{{ mirror_aliyun }}/centos/$releasever/os/$basearch/"
    gpgcheck: yes
    gpgkey: "{{ mirror_aliyun }}/centos/RPM-GPG-KEY-CentOS-7"
    enabled: yes
  become: yes

- name: 配置EPEL国内源
  yum_repository:
    name: aliyun-epel
    description: Aliyun EPEL
    baseurl: "{{ mirror_aliyun }}/epel/$releasever/$basearch/"
    gpgcheck: yes
    gpgkey: "{{ mirror_aliyun }}/epel/RPM-GPG-KEY-EPEL-7"
    enabled: yes
  become: yes

- name: 禁用交换分区
  shell: |
    sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
    swapoff -a
  become: yes

- name: 加载内核模块
  shell: | 
    cat <<EOF | tee /etc/modules-load.d/k8s.conf
    overlay
    br_netfilter
    EOF
    modprobe overlay
    modprobe br_netfilter
  become: yes
   
- name: 配置系统参数
  sysctl:
    name: "{{ item.name }}"
    value: "{{ item.value }}"
    state: present
    reload: yes
  with_items:
    - { name: net.bridge.bridge-nf-call-iptables, value: '1' }
    - { name: net.bridge.bridge-nf-call-ip6tables, value: '1' }
    - { name: net.ipv4.ip_forward, value: '1' }
    - { name: vm.swappiness, value: '0' }
  become: yes

- name: 禁用SELinux
  selinux:
    state: disabled
  become: yes

- name: 停止并禁用防火墙
  systemd:
    name: firewalld
    state: stopped
    enabled: no
  become: yes

- name: 安装基础工具
  yum:
    name:
      - curl
      - wget
      - vim
      - net-tools
      - telnet
      - bash-completion
      - nfs-utils
    state: present
  become: yes

