Refactor: Organize Ansible project structure
- Reorganized Ansible project structure to follow best practices. - Created dedicated directories: , , , , and . - Categorized playbooks into (host-specific) and (service-specific). - Moved all roles into the directory and standardized their naming conventions. - Relocated to for better variable management. - Renamed to to reflect its global variable scope. - Created to correctly set the to the new directory. - Moved and into the directory. - Added to providing explanations for common commands. - Cleaned up directories from all individual roles to centralize version control.
This commit is contained in:
17
roles/linux_config_init/tasks/bashrc_copy.yml
Normal file
17
roles/linux_config_init/tasks/bashrc_copy.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
---
|
||||
- name: Copy /root/.bashrc
|
||||
template:
|
||||
src: ../templates/bashrc
|
||||
dest: /root/.bashrc
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0644'
|
||||
|
||||
|
||||
- name: Copy /home/{{ user }}/.bashrc
|
||||
template:
|
||||
src: ../templates/bashrc
|
||||
dest: /home/{{ user }}/.bashrc
|
||||
owner: "{{ user }}"
|
||||
group: "{{ user }}"
|
||||
mode: '0644'
|
||||
27
roles/linux_config_init/tasks/create_user.yml
Normal file
27
roles/linux_config_init/tasks/create_user.yml
Normal file
@@ -0,0 +1,27 @@
|
||||
---
|
||||
- name: Adding user
|
||||
ansible.builtin.user:
|
||||
name: "{{ user }}"
|
||||
uid: "{{ uid }}"
|
||||
shell: /bin/bash
|
||||
groups: sudo
|
||||
|
||||
- name: Setting ssh key
|
||||
ansible.builtin.blockinfile:
|
||||
state: present
|
||||
owner: "{{ user }}"
|
||||
group: "{{ user }}"
|
||||
insertafter: EOF
|
||||
path: /home/{{ user }}/.ssh/authorized_keys
|
||||
mode: "0644"
|
||||
create: true
|
||||
block: |
|
||||
{{ ssh_key }}
|
||||
when: ssh_key is defined
|
||||
|
||||
- name: Set permissions to .ssh folder
|
||||
ansible.builtin.file:
|
||||
path: /home/{{ user }}/.ssh
|
||||
owner: "{{ user }}"
|
||||
group: "{{ user }}"
|
||||
mode: "0711"
|
||||
13
roles/linux_config_init/tasks/hostname_set.yml
Normal file
13
roles/linux_config_init/tasks/hostname_set.yml
Normal file
@@ -0,0 +1,13 @@
|
||||
---
|
||||
- name: Copy /etc/hosts
|
||||
template:
|
||||
src: ../templates/etc_hosts
|
||||
dest: /etc/hosts
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0664'
|
||||
|
||||
|
||||
- name: Set a hostname
|
||||
ansible.builtin.hostname:
|
||||
name: "{{ host }}"
|
||||
18
roles/linux_config_init/tasks/main.yml
Normal file
18
roles/linux_config_init/tasks/main.yml
Normal file
@@ -0,0 +1,18 @@
|
||||
---
|
||||
# tasks file for linux_config_init
|
||||
- name: System settings
|
||||
ansible.builtin.include_tasks: "{{ item }}"
|
||||
loop:
|
||||
- sudoer_no_passwd.yml
|
||||
- create_user.yml
|
||||
- bashrc_copy.yml
|
||||
- timezone.yml
|
||||
- resolvconf_copy.yml
|
||||
|
||||
- name: Set Pernament IP
|
||||
ansible.builtin.include_tasks: set_perma_ip.yml
|
||||
when: set_ip
|
||||
|
||||
- name: Set Hostname
|
||||
ansible.builtin.include_tasks: hostname_set.yml
|
||||
when: set_hostname
|
||||
8
roles/linux_config_init/tasks/resolvconf_copy.yml
Normal file
8
roles/linux_config_init/tasks/resolvconf_copy.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
- name: Copy /templates/resolvconf
|
||||
template:
|
||||
src: ../templates/resolvconf
|
||||
dest: /etc/resolv.conf
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0644'
|
||||
9
roles/linux_config_init/tasks/set_perma_ip.yml
Normal file
9
roles/linux_config_init/tasks/set_perma_ip.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
---
|
||||
- name: Copy /etc/network/interfaces
|
||||
template:
|
||||
src: ../templates/etc_network_interface
|
||||
dest: /etc/network/interfaces
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0644'
|
||||
notify: networking restart
|
||||
8
roles/linux_config_init/tasks/sudoer_no_passwd.yml
Normal file
8
roles/linux_config_init/tasks/sudoer_no_passwd.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
- name: No password for sudo
|
||||
become: true
|
||||
community.general.sudoers:
|
||||
nopassword: true
|
||||
commands: ALL
|
||||
user: "{{ user }}"
|
||||
name: No password for sudo
|
||||
3
roles/linux_config_init/tasks/timezone.yml
Normal file
3
roles/linux_config_init/tasks/timezone.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
- name: Set timezone to Europe/Prague
|
||||
community.general.timezone:
|
||||
name: Europe/Prague
|
||||
Reference in New Issue
Block a user