Ansible: Installing Google Chrome on Ubuntu
09 Mar 2014 in TIL
Just a quick playbook for installing Google Chrome on Ubuntu. The playbook checks if the Google Chrome apt repo is added, then if it isn't it adds Google's public key, creates the file and then updates the apt cache. Finally, it tries to install Google Chrome.
This playbook's interesting as it uses a combination of register
, ignore_errors
and when
. If the file doesn't exist, the return code of the test
would be 1, indicating that there was an error. I then use that as the when
condition of the following steps to only perform the commands when needed.
yaml
---- hosts: allsudo: Truevars:- apt_file: /etc/apt/sources.list.d/google-chrome.listtasks:- name: Does the Google apt file exist?command: test -fregister: google_apt_existsignore_errors: True- name: Add Google Chrome keyshell: wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -when: google_apt_exists.rc == 1- name: Add Google Chrome repocopy: content="deb http://dl.google.com/linux/chrome/deb/ stable main" dest= owner=root group=root mode=644when: google_apt_exists.rc == 1- name: Update apt cacheapt: update_cache=yeswhen: google_apt_exists.rc == 1- name: Install Google Chromeapt: pkg=google-chrome-stable state=installed