There is always need for installing frequently used packages in a freshly installed Ubuntu Linux. I personally use this when I get new laptop, but it can be changed to manage server or virtual machine instances. My main goal is to play with ansible and use it in something practical for me.
- Install ansible
$ sudo apt-get install ansible ansible-doc |
- Add localhost to ansible hosts file
The file /etc/ansible/hosts should have the following added:
[local] 127.0.0.1 |
- Ping the server
Ping the server to make sure configuration is good. SSH will ask to localhost to known_hosts file.
$ ansible all -m ping The authenticity of host '127.0.0.1 (127.0.0.1)' can't be established. ECDSA key fingerprint is d2:79:49:f4:c4:8d:13:83:50:ce:6c:94:5a:1b:d3:31. Are you sure you want to continue connecting (yes/no)? yes 127.0.0.1 | success >> { "changed": false, "ping": "pong" } |
- Write the basic-packages.yml file
Write YAML file containing ansible command to install the packages, the file name is basic-packages.yml and contains the following*:
--- - name: install packages on a fresh Ubuntu hosts: local user: "{{ username }}" sudo: yes tasks: - name: install all packages apt: name={{ item }} state=present with_items: - apache2 - nginx-full - gnupg - ansible-doc - apache2 - audacity - avidemux - awscli - checkbox-gui - cheese - compizconfig-settings-manager - compiz-plugins-extra - curl - cvs - dos2unix - ec2-api-tools - enigmail - exfat-fuse - exfat-utils - ffmpeg - filezilla - fonts-arabeyes - fonts-droid - gcc - geoip-bin - gimp - google-chrome-stable - gpac - hunspell-ar - hunspell-en-ca - language-pack-ar-base - language-pack-gnome-ar-base - libavcodec-extra - libjs-jquery - libnss-myhostname - mysql-server - nautilus-dropbox - nautilus-image-converter - nmap - openjdk-7-jdk - openssh-server - php5-cli - php5-mysql - python-apport - python-lockfile - python-requests - rdesktop - seahorse-nautilus - subversion - thunderbird-locale-ar - thunderbird-locale-en-gb - traceroute - ttf-mscorefonts-installer - ubuntu-restricted-extras - ubuntu-session - unity-control-center - unity-tweak-tool - unrar - vim - virtualbox-4.3 - vlc - vpnc - whois |
So ansible will attempt to install the above packages on the fresh Ubuntu Desktop.
* Get list of manually installed package explained here
- Dry run ansible playbook
Run the ansible playbook to make sure the configuration doesn’t have any syntax issues and ansible can run the module correctly:
$ ansible-playbook --check basic-packages.yml -e username=myusername --ask-sudo-pass sudo password: PLAY [install packages on a fresh Ubuntu] ************************************* GATHERING FACTS *************************************************************** ok: [127.0.0.1] TASK: [install all packages] ************************************************** changed: [127.0.0.1] => (item=apache2,nginx-full,gnupg,ansible-doc,apache2,audacity,avidemux,awscli,checkbox-gui,cheese,compizconfig-settings-manager,compiz-plugins-extra,curl,cvs,dos2unix,ec2-api-tools,enigmail,exfat-fuse,exfat-utils,ffmpeg,filezilla,fonts-arabeyes,fonts-droid,gcc,geoip-bin,gimp,google-chrome-stable,gpac,hunspell-ar,hunspell-en-ca,language-pack-ar-base,language-pack-gnome-ar-base,libavcodec-extra,libjs-jquery,libnss-myhostname,mysql-client,mysql-server,nautilus-dropbox,nautilus-image-converter,nmap,openjdk-7-jdk,openssh-server,php5-cli,php5-mysql,python-apport,python-lockfile,python-requests,rdesktop,seahorse-nautilus,subversion,thunderbird-locale-ar,thunderbird-locale-en-gb,traceroute,ttf-mscorefonts-installer,ubuntu-restricted-extras,ubuntu-session,unity-control-center,unity-tweak-tool,unrar,vim,virtualbox-4.3,vlc,vpnc,whois) PLAY RECAP ******************************************************************** 127.0.0.1 : ok=2 changed=1 unreachable=0 failed=0 $ |
I use –ask-sudo-pass to pass sudo user password to ansible on remote (local in this case).
- How to use it
On a new installed Ubuntu, install ansible, cope the playbook file to the machine, and run the playbook.
This can be extended of course to changing configuration files using ansible Jinja2 templates.