#0 Common install by OS - debug: msg: "Will install components on ansible_os_family:{{ansible_os_family}},ansible_distribution:{{ ansible_distribution }}, ansible_distribution_major_version: {{ ansible_distribution_major_version }}" - name: Check OS support, if not support, exit ansible fail: msg="OS not supported,exit!" when: ansible_distribution not in common_os_support - include: "{{ansible_os_family}}.yml" - name: Updatedb for mlocate shell: updatedb #2 Pip install - block: - name: pip upgrade(python2 support latest pip version is 20.3.4) shell: python{{ansible_python.version.major}} -m pip install -U "pip < 21.0" failed_when: False - name: Install PyMySQL on pip2 pip: name: PyMySQL version: 0.10.1 extra_args: "-U" executable: pip2 when: ansible_os_family == "RedHat" and (ansible_distribution_major_version == '7' or ansible_distribution_major_version == '2') - name: Install pex requirements module pip: name: pexpect extra_args: "-U" register: pex_install_result failed_when: False - name: Install pymysql requirements module pip: name: PyMySQL extra_args: "-U" register: mysql_install_result failed_when: False when: common_install_python_modules - debug: msg: "{% if pex_install_result.msg is defined %} {{pex_install_result.msg}} {% endif %}" - debug: msg: "{% if mysql_install_result.msg is defined %} {{mysql_install_result.msg}} {% endif %}" #3 Tool install - name: Install tools include_tasks: tools_{{item}}.yml with_items: "{{common_install_tools}}" when: common_install_tools is defined and common_install_tools is not none and common_install_tools != "" and common_install_tools[0]!= "" #4 Configure - name: Create common folder file: path: '/data/{{item}}' state: directory recurse: yes mode: '0755' with_items: - logs - config - cert - apps failed_when: False - block: - name: set a regular hostname, remove "." shell: get_hostname=$(hostname);echo ${get_hostname%%.*} register: common_get_hostname - hostname: name: "{{common_get_hostname.stdout}}" # Install docker - name: Install Docker on {{ansible_distribution}} shell: | curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh when: ansible_distribution != 'Amazon' - block: - name: Add Docker repository and replace $releasever shell: | wget -O /etc/yum.repos.d/docker-ce.repo "https://download.docker.com/linux/centos/docker-ce.repo" sudo sed -i "s/\$releasever/7/g" /etc/yum.repos.d/docker-ce.repo - name: Install all required packages of Docker on {{ansible_distribution}} yum: name: [device-mapper-persistent-data,lvm2,docker-ce,docker-ce-cli,containerd.io,docker-compose-plugin,docker-scan-plugin,docker-ce-rootless-extras] update_cache: yes state: latest when: ansible_distribution == 'Amazon' - name: Add permanently alias for docker compose shell: | alias docker-compose='docker compose' echo "alias docker-compose='docker compose'" >> /etc/profile.d/docker-compose.sh source /etc/profile.d/docker-compose.sh - name: Started and enable Docker service: name: docker enabled: yes state: restarted - name: Check Docker Version shell: sudo sh -c "docker -v 1>> /data/logs/install_version.txt" # Softlink - name: Create a symbolic link file: src: '{{item.src}}' dest: '{{item.dest}}' state: link force: yes with_items: - {src: /data/wwwroot/,dest: /data/apps} - {src: /var/lib/docker/,dest: /data/docker}