【DevOps】Ansible 为服务器集群安装 Chrome 和 ChromeDriver

Ansible 安装 Chrome

之前的服务器集群上,有的安装了 Chrome,有的没安装,且版本有新有旧,这次我们借助 Ansible 将服务器已有的 Chrome 卸载,并安装统一版本的 Chrome;

vim install_chrome.yml

- hosts: servers_all
  become: true
  tasks:
    - name: uninstall old chrome
      shell: "apt remove google-chrome-stable -y"
      ignore_errors: yes  #新增
    - name: mkdir installation_package
      shell: mkdir /usr/installation_package
      ignore_errors: yes
    - name: download Installation package
      get_url: url=https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb dest=/usr/installation_package/google-chrome-stable_current_amd64.deb
    - name: install chrome
      shell: "dpkg -i /usr/installation_package/google-chrome-stable_current_amd64.deb"
    - name: check chrome
      shell: "google-chrome --version"

ansible-playbook install_chrome.yml
ansible servers_all -m shell -a "google-chrome --version"

如果在安装 chrome 时,出现因为依赖关系的报错,可以通过如下命令修复 apt 依赖关系:

sudo apt install -f

Ansible 安装 ChromeDriver

sudo vim install_chromedriver.yml

- hosts: servers_all
  become: true
  tasks:
    - name: install unzip
      shell: apt install unzip
    - name: download chromedriver
      unarchive:
        src: https://npm.taobao.org/mirrors/chromedriver/86.0.4240.22/chromedriver_linux64.zip
        dest: /usr/installation_package
        copy: no
#    - name: unzip chromedriver
#      shell: unzip /usr/installation_package/chromedriver_linux64.zip
    - name: move chromedriver to /usr/local/bin
      shell: mv /usr/installation_package/chromedriver /usr/local/bin
    - name: chmod +x chromedriver
      shell: chmod +x /usr/local/bin/chromedriver
    - name: check chromedriver
      shell: chromedriver --version

ansible-playbook install_chrome.yml
ansible servers_all -m shell -a "chromedriver --version"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值