+ Ubuntu 16.04
+ Ansible 2.5.2
+ Ansible Galaxy 2.5.2
+ Vagrant 2.1.1
+ Virtualbox 5.2.1.12
I. Install python, pip and ansible
- Install python
sudo apt-get install -y python2.7 python-pip
- Install Ansible
II. Update global variables
- Add file vars/main.yml
---
remove_oh_my_zsh_if_existed: false
default_shell: zsh
debug_mode: true
main_user: vagrant
main_dir: "/home/{{main_user}}"
- Add config to playbook.yml
vars_files:
- vars/main.yml
III. Add pre-tasks to preparing base package to install another packages
- Preparing structure by ansible galaxy for pre-tasks
mkdir roles
ansible-galaxy init roles/pre_tasks
- Add code below to roles/pre-tasks/tasks/main.yml
---
- include: update_system.yml
- include: packages.yml
- Add code below to roles/pre-tasks/tasks/update_system.yml
---
- name: apt-get update
raw: apt-get update -qq
- name: install python 2.7 and aptitude
raw: apt-get install -qq python2.7 aptitude
- name: set python 2.7 as default
raw: update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
- Add code below to roles/pre-tasks/tasks/packages.yml
---
- name: Install packages
package:
name: '{{item}}'
state: present
with_items: ['git-core', 'htop', 'curl']
- Add roles pre-tasks to playbook.yml
III. Install and config ZSH
- Preparing structure by ansible galaxy for zsh
ansible-galaxy init roles/zsh
- Add code below to roles/zsh/tasks/main.yml
---
- name: Install ZSH
package:
name: zsh
state: present
- Add roles zsh to playbook.yml
- Preparing structure by ansible galaxy for Oh My ZSH
ansible-galaxy init roles/oh_my_zsh
- Add code below to roles/oh_my_zsh/tasks/main.yml
---
- name: Load install script from server
get_url:
url: https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh
dest: "{{main_dir}}/oh-my-zsh.sh"
mode: 0777
- name: Run script as {{main_user}}
become: true
become_user: "{{main_user}}"
command: "sh -C {{main_dir}}/oh-my-zsh.sh"
- name: Change user ({{main_user}}) shell to {{default_shell}}
become: true
user:
name: main_user
shell: /bin/{{default_shell}}
- Add roles oh_my_zsh to playbook.yml
roles:
- pre-tasks
- zsh
- oh_my_zsh