From 23dc596a0afadb3d41e81f3db599b97d11877c5b Mon Sep 17 00:00:00 2001 From: qiaofeng1227 <76487013@qq.com> Date: Sun, 25 Jun 2023 11:01:50 +0800 Subject: [PATCH] huaweicloud --- apps/roles/role_cloud/defaults/main.yml | 2 +- apps/roles/role_cloud/tasks/main.yml | 133 ++++++++++++------------ install/install.sh | 16 ++- 3 files changed, 81 insertions(+), 70 deletions(-) diff --git a/apps/roles/role_cloud/defaults/main.yml b/apps/roles/role_cloud/defaults/main.yml index 774fc619..2180d345 100644 --- a/apps/roles/role_cloud/defaults/main.yml +++ b/apps/roles/role_cloud/defaults/main.yml @@ -1,2 +1,2 @@ # install Cloud Agent, default is false -cloud_agent: False \ No newline at end of file +cloud_agent: true diff --git a/apps/roles/role_cloud/tasks/main.yml b/apps/roles/role_cloud/tasks/main.yml index 3d286f1d..ba436eea 100644 --- a/apps/roles/role_cloud/tasks/main.yml +++ b/apps/roles/role_cloud/tasks/main.yml @@ -1,92 +1,91 @@ ## - name: Check Cloud - shell : | + shell: | if [ -f "/etc/waagent.conf" ];then echo "azure";fi if [ -d "/usr/local/aegis" ];then echo "alicloud";fi if [ -f "/snap/bin/amazon-ssm-agent.ssm-cli" ];then echo "aws";fi if [ -f "/usr/bin/amazon-ssm-agent" ];then echo "aws";fi if [ -d "/CloudrResetPwdAgent" ];then echo "huaiwei";fi register: cloud - + - debug: msg: "Cloud platform is {{ cloud.stdout}}" - - - block: - - name: Change ubuntu service name - shell: | - ln -sf /usr/lib/systemd/system/walinuxagent.service /usr/lib/systemd/system/waagent.service - systemctl daemon-reload - when: ansible_os_family == 'Debian' - - - name: ResourceDisk EnableSwap - lineinfile: - dest: /etc/waagent.conf - regexp: 'ResourceDisk.Format=n' - line: "ResourceDisk.Format=y" - state: present + - name: Change ubuntu service name + shell: | + ln -sf /usr/lib/systemd/system/walinuxagent.service /usr/lib/systemd/system/waagent.service + systemctl daemon-reload + when: ansible_os_family == 'Debian' - - name: ResourceDisk EnableSwap - lineinfile: - dest: /etc/waagent.conf - regexp: 'ResourceDisk.EnableSwap=n' - line: "ResourceDisk.EnableSwap=y" - state: present + - name: ResourceDisk EnableSwap + lineinfile: + dest: /etc/waagent.conf + regexp: "ResourceDisk.Format=n" + line: "ResourceDisk.Format=y" + state: present - - name: ResourceDisk SwapSizeMB - lineinfile: - dest: /etc/waagent.conf - regexp: 'ResourceDisk.SwapSizeMB=0' - line: "ResourceDisk.SwapSizeMB=4096" - state: present + - name: ResourceDisk EnableSwap + lineinfile: + dest: /etc/waagent.conf + regexp: "ResourceDisk.EnableSwap=n" + line: "ResourceDisk.EnableSwap=y" + state: present - - name: Restart waagnet - service: - name: waagent - state: restarted - enabled: yes + - name: ResourceDisk SwapSizeMB + lineinfile: + dest: /etc/waagent.conf + regexp: "ResourceDisk.SwapSizeMB=0" + line: "ResourceDisk.SwapSizeMB=4096" + state: present + + - name: Restart waagnet + service: + name: waagent + state: restarted + enabled: yes when: cloud.stdout == 'azure' - block: - - name: AWS Configure - apt: - name: ec2-instance-connect - update_cache: yes - when: ansible_os_family == 'Debian' + - name: AWS Configure + apt: + name: ec2-instance-connect + update_cache: yes + when: ansible_os_family == 'Debian' + + - name: AWS Configure + yum: + name: ec2-instance-connect + when: ansible_os_family == 'RedHat' + + - name: Start ec2-instance-connect + service: + name: ec2-instance-connect + state: started + enabled: yes + failed_when: False - - name: AWS Configure - yum: - name: ec2-instance-connect - when: ansible_os_family == 'RedHat' - - - name: Start ec2-instance-connect - service: - name: ec2-instance-connect - state: started - enabled: yes - failed_when: False - when: cloud.stdout == 'aws' - + # install cloud agent - block: - - name: Install Aliyun Aqs and aliyun_assist - shell: | - wget "https://aegis.alicdn.com/download/install/2.0/linux/AliAqsInstall_64.sh" && chmod +x AliAqsInstall_64.sh && ./AliAqsInstall_64.sh sJmepE - wget "https://aliyun-client-assist.oss-accelerate.aliyuncs.com/linux/aliyun_assist_latest.rpm" - rpm -ivh --force aliyun_assist_latest.rpm - #wget "https://aliyun-client-assist.oss-accelerate.aliyuncs.com/linux/aliyun_assist_latest.deb" - #dpkg -r aliyun-assist - systemctl restart aliyun.service - when: cloud.stdout == 'alicloud' - - + - name: Install Aliyun Aqs and aliyun_assist + shell: | + wget "https://aegis.alicdn.com/download/install/2.0/linux/AliAqsInstall_64.sh" && chmod +x AliAqsInstall_64.sh && ./AliAqsInstall_64.sh sJmepE + wget "https://aliyun-client-assist.oss-accelerate.aliyuncs.com/linux/aliyun_assist_latest.rpm" + rpm -ivh --force aliyun_assist_latest.rpm + #wget "https://aliyun-client-assist.oss-accelerate.aliyuncs.com/linux/aliyun_assist_latest.deb" + #dpkg -r aliyun-assist + systemctl restart aliyun.service + when: cloud.stdout == 'alicloud' + + - name: Install huawei agent + shell: curl -k -O 'https://hss-agent.ap-southeast-1.myhuaweicloud.com:10180/package/agent/linux/x86/hostguard.x86_64.deb' && echo 'MASTER_IP=hss-agent.ap-southeast-1.myhuaweicloud.com:10180' > hostguard_setup_config.conf && echo 'SLAVE_IP=hss-agent-slave.ap-southeast-1.myhuaweicloud.com:10180' >> hostguard_setup_config.conf && echo 'ORG_ID=' >> hostguard_setup_config.conf && dpkg -i hostguard.x86_64.deb && rm -f hostguard_setup_config.conf && rm -f hostguard.x86_64.deb + when: ansible_os_family == "RedHat" and cloud.stdout == 'huawei' + + - name: Install huawei agent + shell: curl -k -O 'https://hss-agent.ap-southeast-1.myhuaweicloud.com:10180/package/agent/linux/x86/hostguard.x86_64.rpm' && echo 'MASTER_IP=hss-agent.ap-southeast-1.myhuaweicloud.com:10180' > hostguard_setup_config.conf && echo 'SLAVE_IP=hss-agent-slave.ap-southeast-1.myhuaweicloud.com:10180' >> hostguard_setup_config.conf && echo 'ORG_ID=' >> hostguard_setup_config.conf && rpm -ivh hostguard.x86_64.rpm && rm -f hostguard_setup_config.conf && rm -f hostguard.x86_64.rpm + when: ansible_os_family == "Debian" and cloud.stdout == 'huawei' - - name: Install HUAWEICLOUD Agent - shell: wget https://telescope-ap-southeast-1.obs.ap-southeast-1.myhuaweicloud.com/scripts/agentBatchPackage.sh && chmod 755 agentBatchPackage.sh && ./agentBatchPackage.sh - args: - chdir: /usr/local - when: cloud.stdout == 'huawei' when: cloud_agent diff --git a/install/install.sh b/install/install.sh index df6cca69..82c79c82 100644 --- a/install/install.sh +++ b/install/install.sh @@ -151,8 +151,20 @@ fi InstallDocker(){ -echo "Prepare to install Docker ..." - +if command -v docker &> /dev/null +then + echo "Docker is installed, update..." + if command -v apt > /dev/null;then + sudo apt -y install --only-upgrade docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin + elif command -v dnf > /dev/null;then + sudo dnf update -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin + elif command -v yum > /dev/null;then + sudo yum update -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin + fi + return +else + echo "Docker is not installed, start to install..." +fi if [ "$os_type" == 'CentOS' ];then curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh fi