Skip to content

Instantly share code, notes, and snippets.

@sajalshres
Last active September 21, 2022 15:53
Show Gist options
  • Save sajalshres/a31c4ba6b893353ce89414a92edb41b1 to your computer and use it in GitHub Desktop.
Save sajalshres/a31c4ba6b893353ce89414a92edb41b1 to your computer and use it in GitHub Desktop.
Ansible playbook for local environment
devmachine ansible_connection=local
---
- name: Install Base Packages
hosts: all
tasks:
- name: Install aptitude using apt
become: true
become_user: root
apt: name=aptitude state=latest update_cache=yes force_apt_get=yes
- name: Install required system packages
become: true
become_user: root
apt:
pkg:
- net-tools
- apt-transport-https
- ca-certificates
- curl
- lsb-release
- gnupg
- software-properties-common
- python3-pip
- virtualenv
- python3-setuptools
- vim
- unzip
state: present
- name: Install Python
hosts: all
vars:
- version: 3.9
tasks:
- name: Check is python {{ version }} installed
shell: "command -v python{{ version }}"
register: python_exists
ignore_errors: true
- name: Add deadsnakes PPA to apt
become: true
become_user: root
apt_repository:
repo: ppa:deadsnakes/ppa
validate_certs: false
when: python_exists is failed
- name: Install aptitude using apt
become: true
become_user: root
apt: name=aptitude state=latest update_cache=yes force_apt_get=yes
when: python_exists is failed
- name: Install python {{ version }}
become: true
become_user: root
apt:
name:
- "python{{ version }}"
- "python{{ version }}-dev"
- "python{{ version }}-venv"
state: present
when: python_exists is failed
- name: Make sure associated pip is installed for user environment
shell: "python{{ version }} -m ensurepip --default-pip --user"
when: python_exists is failed
- name: Install node version manager
hosts: all
vars:
- version: 0.39.1
tasks:
- name: check is nvm {{ version }} installed
shell: bash -ilc "command -v nvm"
register: nvm_exists
ignore_errors: true
- name: download install script
get_url:
url: "https://raw.githubusercontent.com/nvm-sh/nvm/v{{ version }}/install.sh"
dest: /tmp/nvm_install.sh
mode: 0755
when: nvm_exists is failed
- name: install nvm {{ version }}
shell: /tmp/nvm_install.sh
args:
creates: "~/.nvm/nvm.sh"
when: nvm_exists is failed
- name: cleanup install
file:
path: /tmp/nvm_install.sh
state: absent
- name: install latest node
shell: bash -ilc "nvm install node"
- name: use latest node
shell: bash -ilc "nvm use node"
- name: Install oh-my-posh
hosts: all
vars:
username: "{{ ansible_user_id }}"
tasks:
- name: download oh-my-posh binary
become: true
become_user: root
get_url:
url: https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/posh-linux-amd64
dest: /usr/local/bin/oh-my-posh
mode: a+x
- name: create oh my posh themes directory
become: true
become_user: "{{ username }}"
file:
path: ~/.poshthemes
state: directory
- name: cleanup old themes
become: true
become_user: "{{ username }}"
shell: rm -rf ~/.poshthemes/*.json
- name: unzip download themes
become: true
become_user: "{{ username }}"
unarchive:
src: https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/themes.zip
dest: ~/.poshthemes
remote_src: yes
- name: change prompt
become: true
become_user: "{{ username }}"
lineinfile:
dest: ~/.bashrc
line: 'eval "$(oh-my-posh --init --shell bash --config https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/v$(oh-my-posh --version)/themes/iterm2.omp.json)"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment