diff --git a/ansible/ansible.cfg b/ansible/ansible.cfg new file mode 100644 index 0000000..c78bbc2 --- /dev/null +++ b/ansible/ansible.cfg @@ -0,0 +1,8 @@ +[defaults] + +action_warnings=True +force_color=False +nocolor=False +nocows=True + +home=~/ansible-lol/ansible diff --git a/ansible/inventory b/ansible/inventory new file mode 100644 index 0000000..55a661f --- /dev/null +++ b/ansible/inventory @@ -0,0 +1,19 @@ +all: + children: + debian: + hosts: + reverse-proxy: + git: + labolyon-fr: + matrix: + wiki: + blogs: + mail: + radius: + ansible: + dn42-router: + lolix-rs1: + lolix-ixpman: + dns: + mosquitto: + monitoring: diff --git a/ansible/playbooks/debug.yml b/ansible/playbooks/debug.yml new file mode 100644 index 0000000..40e2ce4 --- /dev/null +++ b/ansible/playbooks/debug.yml @@ -0,0 +1,11 @@ +--- +# Playbook to debug and display variables + +- name: Display all variables/facts known for a host + hosts: all + become: no + tasks: + - name: Display all variables/facts known for a host + tags: debug_info + debug: + var: hostvars[inventory_hostname] diff --git a/ansible/playbooks/dns.yml b/ansible/playbooks/dns.yml new file mode 100644 index 0000000..0415111 --- /dev/null +++ b/ansible/playbooks/dns.yml @@ -0,0 +1,8 @@ +--- +# Playbook to set up the local DNS resolver + +- name: Install and configure the local DNS resolver + hosts: dns + become: yes + roles: + - dns-internal diff --git a/ansible/playbooks/setup.yml b/ansible/playbooks/setup.yml new file mode 100644 index 0000000..7b73814 --- /dev/null +++ b/ansible/playbooks/setup.yml @@ -0,0 +1,9 @@ +--- +# Playbook to set up the servers + +- name: Configure access and install work tools + hosts: all + become: yes + roles: + - tools + - users diff --git a/ansible/roles/dns-internal/handlers/main.yml b/ansible/roles/dns-internal/handlers/main.yml new file mode 100644 index 0000000..cc50c44 --- /dev/null +++ b/ansible/roles/dns-internal/handlers/main.yml @@ -0,0 +1,6 @@ +--- +## Reload NSD on changes +- name: restart nsd + ansible.builtin.service: + name: nsd + state: restarted diff --git a/ansible/roles/dns-internal/tasks/main.yml b/ansible/roles/dns-internal/tasks/main.yml new file mode 100644 index 0000000..1ff9583 --- /dev/null +++ b/ansible/roles/dns-internal/tasks/main.yml @@ -0,0 +1,35 @@ +--- + +- name: Install packages for local resolver + tags: resolver-install + ansible.builtin.package: + name: + - nsd + - git + state: latest + +- name: NSD - Enable service + tags: nsd-enable + ansible.builtin.service: + name: 'nsd' + state: started + enabled: yes + +- name: NSD - Define configuration + tags: nsd-configure + ansible.builtin.template: + src: nsd.conf + dest: /etc/nsd/nsd.conf + validate: /usr/sbin/nsd-checkconf %s + backup: yes + notify: restart nsd + +- name: Auto-update the git repo for the internal zone + tags: nsd-dns-gitupdate + ansible.builtin.git: + repo: https://git.labolyon.fr/LOL-si/dns-lolinternal.git + dest: /srv/nsd/ + version: main + update: yes + notify: + - restart nsd diff --git a/ansible/roles/dns-internal/templates/nsd.conf b/ansible/roles/dns-internal/templates/nsd.conf new file mode 100644 index 0000000..6c13148 --- /dev/null +++ b/ansible/roles/dns-internal/templates/nsd.conf @@ -0,0 +1,22 @@ +server: + server-count: 1 + hide-version: yes + debug-mode: no + verbosity: 2 + zonesdir: "/srv/nsd/" + +remote-control: + control-enable: yes + control-interface: /var/run/nsd.sock + +zone: + name: "int.labolyon.fr" + zonefile: "int.labolyon.fr.zone" + +zone: + name: "labolyon.dn42" + zonefile: "labolyon.dn42.zone" + +zone: + name: "labolyon.fr" + zonefile: "labolyon.fr.zone" diff --git a/ansible/roles/tools/tasks/main.yml b/ansible/roles/tools/tasks/main.yml new file mode 100644 index 0000000..3efac62 --- /dev/null +++ b/ansible/roles/tools/tasks/main.yml @@ -0,0 +1,10 @@ +--- + +- name: Load variables + include_vars: "{{ ansible_os_family|lower }}.yml" + +- name: Tools | install common packages for servers + ansible.builtin.package: + name: '{{ common_packages }}' + state: latest + tags: common-tools diff --git a/ansible/roles/tools/vars/debian.yml b/ansible/roles/tools/vars/debian.yml new file mode 100644 index 0000000..ed1a1fc --- /dev/null +++ b/ansible/roles/tools/vars/debian.yml @@ -0,0 +1,15 @@ +--- +# vars file for tools role +common_packages: + - htop + - neofetch + - curl + - bash + - figlet + - vim + - rsync + - needrestart + - lynis + - apt-listbugs + - dnsutils + - libpam-radius-auth diff --git a/ansible/roles/users/tasks/main.yml b/ansible/roles/users/tasks/main.yml new file mode 100644 index 0000000..5944aa0 --- /dev/null +++ b/ansible/roles/users/tasks/main.yml @@ -0,0 +1,52 @@ +--- + +- name: Load variables + include_vars: "{{ ansible_os_family|lower }}.yml" + +- name: Linux | Set bash path for Linux hosts + ansible.builtin.set_fact: + bash_path: /bin/bash + +- name: All hosts | Create the users + ansible.builtin.user: + name: "{{ item.name }}" + home: /home/{{ item.name }} + shell: '{{ bash_path }}' + groups: sudo + append: true + state: present + with_items: "{{ user_details }}" + +- name: All hosts | Set up home directory permissions for users + ansible.builtin.file: + path: /home/{{ item.name }} + owner: "{{ item.name }}" + state: directory + mode: 0700 + with_items: "{{ user_details }}" + +- name: All hosts | Set up ssh directory for users + ansible.builtin.file: + path: /home/{{ item.name }}/.ssh + owner: "{{ item.name }}" + state: directory + mode: 0700 + with_items: "{{ user_details }}" + +#- name: All hosts | Add ssh keys for allowing connections +# ansible.builtin.template: +# src: authorized_keys +# dest: /home/vinishor/.ssh/authorized_keys +# owner: vinishor +# mode: 0600 + +- name: Linux | Correct sudoers file permissions for ansible user + ansible.builtin.file: + path: "/etc/sudoers.d/ansible" + owner: root + group: root + mode: 0640 + +- name: Linux | Define MOTD file + ansible.builtin.shell: + cmd: figlet -t {{ inventory_hostname_short | quote }} > /etc/motd diff --git a/ansible/roles/users/vars/debian.yml b/ansible/roles/users/vars/debian.yml new file mode 100644 index 0000000..bfdd4d8 --- /dev/null +++ b/ansible/roles/users/vars/debian.yml @@ -0,0 +1,7 @@ +--- + +user_details: + - { name: vincent } + - { name: mirsal } + - { name: jerome } + - { name: sofian }