Skip to content

Instantly share code, notes, and snippets.

@jtprogru
Created April 22, 2021 09:37
Show Gist options
  • Save jtprogru/6af942200f4adc6cadca844f2470641c to your computer and use it in GitHub Desktop.
Save jtprogru/6af942200f4adc6cadca844f2470641c to your computer and use it in GitHub Desktop.
Playbook для создания моего пользователя и базовой настройки окружения
---
- name: "Персональная базовая конфигурация окружения."
hosts: all:!localhost
become: true
vars:
sysops_employer:
name: "jtprogru"
pass: "!vault |
$ANSIBLE_VAULT;1.1;AES256
61316338323363653732376531656330663266656236613436643236353061366533353661333634
3031623137336332646462633537633261613062343565320a396634343964313630613533393830
66326431353138393830343632373736613430326233346262393230373635663233646563346461
3133303133663332380a376534643266333735343736613261633033363638303330353532353763
3763"
key: https://github.com/jtprogru.keys
group: "admins"
bash_profile_content: |
export HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S "
source ~/.bashrc
myvimrc: |
syntax on
colorscheme delek
set number
set expandtab
set tabstop=4
set enc=utf-8
set guicursor=n-v-c:block-Cursor
set hlsearch
set incsearch
tasks:
- name: "создаем для начала группу для пользователя"
group:
name: "{{ sysops_employer.group }}"
state: present
- name: "создаем учетную запись пользователя под которым будем ходить на сервер"
user:
name: "{{ sysops_employer.name }}"
shell: /bin/bash
groups: "{{ sysops_employer.group }}"
password: "{{ sysops_employer.pass | password_hash('sha512') }}"
update_password: on_create
- name: "правим файл sudoers и проверяем его перед сохранением"
lineinfile:
path: /etc/sudoers
state: present
regexp: '^%{{ sysops_employer.group }} ALL='
line: '%{{ sysops_employer.group }} ALL=(ALL) NOPASSWD: ALL'
validate: /usr/sbin/visudo -cf %s
- name: "добавляем созданному пользователю свой ключ"
authorized_key:
user: "{{ sysops_employer.name }}"
key: "{{ sysops_employer.key }}"
- name: "Create .bash_profile"
copy:
dest: "/home/{{ sysops_employer.name }}/.bash_profile"
content: "{{ bash_profile_content }}"
- name: "Add bashrc to bash_profile."
lineinfile:
path: "/home/{{ sysops_employer.name }}/.bash_profile"
line: 'source ~/.bashrc'
state: present
- name: "Install VIM."
package:
name: vim
state: latest
- name: "Create .vimrc."
copy:
dest: "{{ item }}"
content: "{{ myvimrc }}"
with_items:
- "/home/{{ sysops_employer.name }}/.vimrc"
- "/root/.vimrc"
- name: "Update PS1"
lineinfile:
path: "{{ item }}"
regexp: "^export PS1"
line: |
export PS1='\[\033[01;31m\]\u\[\033[01;33m\]@\[\033[01;36m\]\h \[\033[01;33m\]\w \[\033[01;35m\]\$ \[\033[00m\]'
state: present
with_items:
- "/home/{{ sysops_employer.name }}/.bashrc"
- "/root/.bashrc"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment