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"