Skip to content

Instantly share code, notes, and snippets.

@douglascodes
Last active September 17, 2017 21:46
Show Gist options
  • Save douglascodes/cb8b8d2763a1560df9925688a94a1972 to your computer and use it in GitHub Desktop.
Save douglascodes/cb8b8d2763a1560df9925688a94a1972 to your computer and use it in GitHub Desktop.
An ansible file for setting up my default config
---
- hosts: redhat_aws
vars:
remote_user: ec2-user
target_user: myUserName
tasks:
- name: 1.Check if EPEL repo is already configured.
stat: path=/etc/yum.repos.d/epel.repo
register: epel_repofile_result
- name: 2.Install EPEL repo.
yum:
name: "https://dl.fedoraproject.org/pub/epel/epel-release-latest-{{ ansible_distribution_major_version }}.noarch.rpm"
state: present
register: result
when: not epel_repofile_result.stat.exists
become: true
- name: 3.Import EPEL GPG key.
rpm_key:
key: "https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-{{ ansible_distribution_major_version }}"
state: present
when: not epel_repofile_result.stat.exists
become: true
- name: upgrade all packages
yum:
name: '*'
state: latest
become: true
- name: install regular software
yum: pkg={{item}} state=installed
with_items:
- nano
- zsh
- tmux
- git
- mc
- emacs-nox
- kernel-headers
- zip
- pciutils
- deltarpm
- postgresql
- inotify-tools
- python34
- bind-utils
- jq
become: true
- name: Disable selinux
selinux:
state: disabled
become: true
- name: Create "{{ target_user }}" user with zsh and .ssh/authorized_keys
user:
name: "{{ target_user }}"
shell: /usr/bin/zsh
groups: wheel,adm,users
append: yes
become: true
- name: Adds "{{ target_user }}" public key to authorized_keys
authorized_key:
user: "{{ target_user }}"
manage_dir: yes
key: PUTYOURPUBLICKEYHERE
become: true
become_user: "{{ target_user }}"
- name: Creates directory
file:
path: ~/src
state: directory
become: true
become_user: "{{ target_user }}"
- name: Download latest oh-my-zsh
git:
repo: 'https://github.com/robbyrussell/oh-my-zsh.git'
dest: ~/src/oh-my-zsh
become: true
become_user: "{{ target_user }}"
- name: Install oh-my-zsh
command: /bin/bash -c ./tools/install.sh
args:
chdir: ~/src/oh-my-zsh
creates: ~/.oh-my-zsh
become: true
become_user: "{{ target_user }}"
- name: Checks for .zshrc
stat:
path: ~/.zshrc
register: zshrc
become: true
become_user: "{{ target_user }}"
- name: Set default theme
replace:
path: ~/.zshrc
regexp: 'ZSH_THEME="robbyrussell"'
replace: 'ZSH_THEME="rkj"'
when: zshrc.stat.exists
become: true
become_user: "{{ target_user }}"
- name: Delete "{{ target_user }}" password
command: /usr/bin/passwd -d "{{ target_user }}"
become: true
- name: Expire "{{ target_user }}" password
command: /usr/bin/chage -d0 "{{ target_user }}"
become: true
- name: Install oh-my-zsh
command: /usr/sbin/shutdown -r 1
become: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment