From 694ea4665ea6b76af892b05e4ba9137255fe5b33 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 4 Dec 2022 02:28:25 -0500 Subject: [PATCH] Add a hosts role to set /etc/hosts. --- ansible/playbook.yaml | 1 + ansible/roles/hosts/defaults/main.yaml | 5 ++++ ansible/roles/hosts/tasks/common.yaml | 22 ++++++++++++++ ansible/roles/hosts/tasks/freebsd.yaml | 5 ++++ ansible/roles/hosts/tasks/linux.yaml | 21 ++++++++++++++ ansible/roles/hosts/tasks/main.yaml | 2 ++ ansible/roles/hosts/tasks/peruser.yaml | 29 +++++++++++++++++++ .../roles/hosts/tasks/peruser_freebsd.yaml | 0 ansible/roles/hosts/tasks/peruser_linux.yaml | 0 9 files changed, 85 insertions(+) create mode 100644 ansible/roles/hosts/defaults/main.yaml create mode 100644 ansible/roles/hosts/tasks/common.yaml create mode 100644 ansible/roles/hosts/tasks/freebsd.yaml create mode 100644 ansible/roles/hosts/tasks/linux.yaml create mode 100644 ansible/roles/hosts/tasks/main.yaml create mode 100644 ansible/roles/hosts/tasks/peruser.yaml create mode 100644 ansible/roles/hosts/tasks/peruser_freebsd.yaml create mode 100644 ansible/roles/hosts/tasks/peruser_linux.yaml diff --git a/ansible/playbook.yaml b/ansible/playbook.yaml index 91a55c7..26470e7 100644 --- a/ansible/playbook.yaml +++ b/ansible/playbook.yaml @@ -13,6 +13,7 @@ - firewall - cpu - ntp + - hosts - build - sound - graphics diff --git a/ansible/roles/hosts/defaults/main.yaml b/ansible/roles/hosts/defaults/main.yaml new file mode 100644 index 0000000..b3a7822 --- /dev/null +++ b/ansible/roles/hosts/defaults/main.yaml @@ -0,0 +1,5 @@ +etc_hosts: + 10.216.1.6: + - media + 10.216.1.12: + - odo diff --git a/ansible/roles/hosts/tasks/common.yaml b/ansible/roles/hosts/tasks/common.yaml new file mode 100644 index 0000000..32cb8ba --- /dev/null +++ b/ansible/roles/hosts/tasks/common.yaml @@ -0,0 +1,22 @@ +- name: Set the /etc/hosts + ansible.builtin.lineinfile: + path: /etc/hosts + regexp: '^{{ item.key | regex_escape() }}' + line: "{{ item.key }} {{ item.value | join(' ') }}" + loop: "{{ etc_hosts | dict2items }}" + +- import_tasks: tasks/freebsd.yaml + when: 'os_flavor == "freebsd"' + +- import_tasks: tasks/linux.yaml + when: 'os_flavor == "linux"' + +- include_tasks: + file: tasks/peruser.yaml + apply: + become: yes + become_user: "{{ initialize_user }}" + when: users is defined + loop: "{{ users | dict2items | community.general.json_query('[?value.initialize==`true`].key') }}" + loop_control: + loop_var: initialize_user diff --git a/ansible/roles/hosts/tasks/freebsd.yaml b/ansible/roles/hosts/tasks/freebsd.yaml new file mode 100644 index 0000000..b417174 --- /dev/null +++ b/ansible/roles/hosts/tasks/freebsd.yaml @@ -0,0 +1,5 @@ +# - name: Install packages +# package: +# name: +# - foo +# state: present diff --git a/ansible/roles/hosts/tasks/linux.yaml b/ansible/roles/hosts/tasks/linux.yaml new file mode 100644 index 0000000..429ad91 --- /dev/null +++ b/ansible/roles/hosts/tasks/linux.yaml @@ -0,0 +1,21 @@ +# - name: Build aur packages +# register: buildaur +# become_user: "{{ build_user.name }}" +# command: "aurutils-sync --no-view {{ item }}" +# args: +# creates: "/var/cache/pacman/custom/{{ item }}-*.pkg.tar.*" +# loop: +# - foo + +# - name: Update cache +# when: buildaur.changed +# pacman: +# name: [] +# state: present +# update_cache: true + +# - name: Install packages +# package: +# name: +# - foo +# state: present diff --git a/ansible/roles/hosts/tasks/main.yaml b/ansible/roles/hosts/tasks/main.yaml new file mode 100644 index 0000000..57498ba --- /dev/null +++ b/ansible/roles/hosts/tasks/main.yaml @@ -0,0 +1,2 @@ +- import_tasks: tasks/common.yaml + when: etc_hosts is defined diff --git a/ansible/roles/hosts/tasks/peruser.yaml b/ansible/roles/hosts/tasks/peruser.yaml new file mode 100644 index 0000000..111e886 --- /dev/null +++ b/ansible/roles/hosts/tasks/peruser.yaml @@ -0,0 +1,29 @@ +- include_role: + name: per_user + +# - name: Create directories +# file: +# name: "{{ account_homedir.stdout }}/{{ item }}" +# state: directory +# mode: 0700 +# owner: "{{ account_name.stdout }}" +# group: "{{ group_name.stdout }}" +# loop: +# - ".config/foo" + +# - name: Copy files +# copy: +# src: "files/{{ item.src }}" +# dest: "{{ account_homedir.stdout }}/{{ item.dest }}" +# mode: 0600 +# owner: "{{ account_name.stdout }}" +# group: "{{ group_name.stdout }}" +# loop: +# - src: foo.conf +# dest: .config/foo/foo.conf + +- import_tasks: tasks/peruser_freebsd.yaml + when: 'os_flavor == "freebsd"' + +- import_tasks: tasks/peruser_linux.yaml + when: 'os_flavor == "linux"' diff --git a/ansible/roles/hosts/tasks/peruser_freebsd.yaml b/ansible/roles/hosts/tasks/peruser_freebsd.yaml new file mode 100644 index 0000000..e69de29 diff --git a/ansible/roles/hosts/tasks/peruser_linux.yaml b/ansible/roles/hosts/tasks/peruser_linux.yaml new file mode 100644 index 0000000..e69de29