first commit
Marco Andronaco andronacomarco@gmail.com
Thu, 26 Jan 2023 10:37:05 +0100
25 files changed,
314 insertions(+),
0 deletions(-)
jump to
A
ansible.cfg
@@ -0,0 +1,5 @@
+[defaults] +INVENTORY = hosts.yml + +[ssh_connections] +pipelining = true
A
base.yml
@@ -0,0 +1,7 @@
+--- +- hosts: all + become: yes + + tasks: + - import_tasks: tasks/essential.yml +
A
deploy.yml
@@ -0,0 +1,4 @@
+--- +- import_playbook: base.yml +- import_playbook: python.yml +- import_playbook: node.yml
A
group_vars/all/vars.yml
@@ -0,0 +1,8 @@
+packages: + - neovim + - btop + - firefox + - tmux + - git + +username: "{{ ansible_user }}"
A
group_vars/fasco/vars.yml
@@ -0,0 +1,7 @@
+subnet: !vault | + $ANSIBLE_VAULT;1.1;AES256 + 61336638663064343534643836313136343766386566303738626632653638623732376165363032 + 6238623435656631633737616338636265656237333766360a326161386365393032303965663164 + 32663833343333363635623730333835373463336337613732323961393766623430633238623162 + 6538633633386663630a323232613238666431333233316337383462323839376563656461376138 + 6531
A
group_vars/home/vars.yml
@@ -0,0 +1,7 @@
+home_ip: !vault | + $ANSIBLE_VAULT;1.1;AES256 + 35633034373635373931343161356266663066393165363930663632613166653336383065353235 + 6535643338393432386534323033383361363463616532300a343363383931623932643735333661 + 64383333353139336536633363613539663964303337643861393336343838373932386538626436 + 3137633839313030390a316162346465306331613663323165666263613763383564613037396438 + 3934
A
group_vars/node/vars.yml
@@ -0,0 +1,21 @@
+node_packages: + - nodejs + - npm + +simple_discord_music_bot_app_id: !vault | + $ANSIBLE_VAULT;1.1;AES256 + 39323463373036353664356165626534656630356365646161353131373230313139316237383362 + 3634396165353839383632303631613931663738336664620a633838653835383065643666326236 + 36396632323835373531653631383332313538663836373637346362663166653865313061373930 + 3934643632366466310a333563653633653137326338373534613863393966336139663264653164 + 62393661656131336639623334643832363634653362623731353366633937316335 +simple_discord_music_bot_token: !vault | + $ANSIBLE_VAULT;1.1;AES256 + 62396232646433386536373065666534643765623431363833656135613662363739303864626336 + 6333356163363335393535613266666561363437633136620a393762646566363632366632343465 + 36643136383032393061643438643334363530646562616637326566353364336466323466386633 + 6237336537343761350a663333323337386638376131393966333165366566323234373061646162 + 63643435373033316132396536393039646165326434396334663230373132303062333538386136 + 31643862663633313532346637313533663833613566326339363663346534393034653534653463 + 37353064373464653931363738666264313035306463373963663739343339363330306364376363 + 34653665666665356130
A
group_vars/python/vars.yml
@@ -0,0 +1,16 @@
+groupgardenbot_token: !vault | + $ANSIBLE_VAULT;1.1;AES256 + 33656632613063663665313062383635326137346238313038653735346566613735666464333630 + 3739366631626530353231363862306639366562643836300a613439656262326534393664616263 + 38616234363233343666633737336139326235303235663764326435663034303835393635333037 + 3937646266353731330a363733393932306366386230626139383266666161396161646638643231 + 62343831613663313761343766343565663339323137353466646531383234653635343830663739 + 6438333061626666323764656335376334376630613264386535 +python_meme_bot_token: !vault | + $ANSIBLE_VAULT;1.1;AES256 + 33313034613237313061653539323464306332653439623339323136343131633938633562633632 + 3565666339626336636265356666393261316564643666630a636234643634663265666235353630 + 33323439646238666461353832656239386661623237623639613361656363663638666537333032 + 3738623361636532640a333330336363643433343933626436616135643638376163303361633139 + 63366639383665303436333964633037666533303165336338376236326134636439323632626237 + 3530633732623138386232306138346138383562656362643663
A
hosts.yml
@@ -0,0 +1,31 @@
+all: + children: + fasco: + children: + python: + hosts: + grazia: + ansible_host: "{{ subnet }}214" + node: + hosts: + corrado: + ansible_host: "{{ subnet }}78" + ssh: + hosts: + federica: + ansible_host: "{{ subnet }}186" + aurora: + ansible_host: "{{ subnet }}188" + mattia: + ansible_host: "{{ subnet }}199" + vars: + ansible_user: "user" + home: + hosts: + marco: + ansible_host: "{{ home_ip }}" + vars: + ansible_user: "marco" + vars: + ansible_connection: "ssh" + ansible_ssh_private_key_file: "~/.ssh/id_rsa"
A
node.yml
@@ -0,0 +1,6 @@
+--- +- hosts: corrado + become: yes + + roles: + - { role: node_stuff, user: "{{ username }}" }
A
python.yml
@@ -0,0 +1,6 @@
+--- +- hosts: grazia + become: yes + + roles: + - { role: python_stuff, user: "{{ username }}" }
A
reboot-fasco.yml
@@ -0,0 +1,6 @@
+--- +- hosts: fasco + become: yes + + tasks: + - import_tasks: tasks/reboot.yml
A
roles/node_stuff/defaults/main.yaml
@@ -0,0 +1,10 @@
+--- +user: "user" +repo_dir: "/home/{{ user }}/Scaricati/" + +simple_discord_music_bot: simple-discord-music-bot + +node_repos: +- "{{ simple_discord_music_bot }}" + +git_url: "https://github.com/BiRabittoh/"
A
roles/node_stuff/tasks/main.yaml
@@ -0,0 +1,37 @@
+- name: Install essential packages + package: + name: "{{ packages + node_packages }}" + state: latest + +- name: Git pull on node repositories + become: false + git: + repo: "{{ git_url }}{{ item }}" + dest: "{{ repo_dir }}{{ item }}" + update: yes + version: sp + loop: "{{ node_repos }}" + +- name: Create simple-discord-music-bot config.js + become: false + template: + src: templates/config.json.j2 + dest: "{{ repo_dir }}{{ simple_discord_music_bot }}/config.json" + +- name: Install packages based on package.json. + community.general.npm: + path: "{{ repo_dir }}{{ item }}" + loop: "{{ node_repos }}" + +- name: Create node systemd service files + template: + src: templates/node.service.j2 + dest: "/etc/systemd/system/{{ item }}.service" + loop: "{{ node_repos }}" + +- name: Enable and start node services + ansible.builtin.service: + name: "{{ item }}" + enabled: yes + state: started + loop: "{{ node_repos }}"
A
roles/node_stuff/templates/config.json.j2
@@ -0,0 +1,4 @@
+{ + "applicationId": "{{ simple_discord_music_bot_app_id }}", + "token": "{{ simple_discord_music_bot_token }}" +}
A
roles/node_stuff/templates/node.service.j2
@@ -0,0 +1,17 @@
+[Unit] +Description=A NodeJS project. +After=syslog.target network.target + +[Service] +Type=simple +Restart=always +RestartSec=1 +WorkingDirectory={{ repo_dir }}{{ item }} +ExecStart=/usr/bin/npm start +User={{ user }} +StandardOutput=syslog +StandardError=syslog +SyslogIdentifier= {{ item }} + +[Install] +WantedBy=multi-user.target
A
roles/python_stuff/defaults/main.yaml
@@ -0,0 +1,12 @@
+--- +user: "user" +repo_dir: "/home/{{ user }}/Scaricati/" + +groupgardenbot: groupgardenbot +python_meme_bot: python-meme-bot + +python_repos: + - "{{ groupgardenbot }}" + - "{{ python_meme_bot }}" + +git_url: "https://github.com/BiRabittoh/"
A
roles/python_stuff/tasks/main.yaml
@@ -0,0 +1,44 @@
+- name: Git pull on python repositories + become: false + git: + repo: "{{ git_url }}{{ item }}" + dest: "{{ repo_dir }}{{ item }}" + update: yes + version: master + loop: "{{ python_repos }}" + +- name: Install python-setuptools + community.general.pacman: + name: python-setuptools + state: present + +- name: Install specified python requirements in indicated virtualenv + ansible.builtin.pip: + requirements: "{{ repo_dir }}{{ item }}/requirements.txt" + virtualenv: "{{ repo_dir }}{{ item }}/venv" + loop: "{{ python_repos }}" + +- name: Create python-meme-bot .env file + become: false + template: + src: templates/.env.j2 + dest: "{{ repo_dir }}{{ python_meme_bot }}/.env" + +- name: Create groupgardenbot .env file + become: false + template: + src: templates/.env2.j2 + dest: "{{ repo_dir }}{{ groupgardenbot }}/.env" + +- name: Create python systemd service files + template: + src: templates/python.service.j2 + dest: "/etc/systemd/system/{{ item }}.service" + loop: "{{ python_repos }}" + +- name: Enable and start python services + ansible.builtin.service: + name: "{{ item }}" + enabled: yes + state: started + loop: "{{ python_repos }}"
A
roles/python_stuff/templates/python.service.j2
@@ -0,0 +1,17 @@
+[Unit] +Description=A Python project. +After=syslog.target network.target + +[Service] +Type=simple +Restart=always +RestartSec=1 +WorkingDirectory={{ repo_dir }}{{ item }} +ExecStart={{ repo_dir }}{{ item }}/venv/bin/python {{ repo_dir }}{{ item }}/main.py +User={{ user }} +StandardOutput=syslog +StandardError=syslog +SyslogIdentifier= {{ item }} + +[Install] +WantedBy=multi-user.target
A
tasks/essential.yml
@@ -0,0 +1,42 @@
+- name: Update packages + community.general.pacman: + update_cache: true + upgrade: true + +- name: Install essential packages + package: + name: "{{ packages }}" + state: latest + +- name: Create the `aur_builder` user + become: yes + ansible.builtin.user: + name: aur_builder + create_home: yes + group: wheel + +- name: Allow the `aur_builder` user to run `sudo pacman` without a password + become: yes + ansible.builtin.lineinfile: + path: /etc/sudoers.d/11-install-aur_builder + line: 'aur_builder ALL=(ALL) NOPASSWD: /usr/bin/pacman' + create: yes + validate: 'visudo -cf %s' + +- name: Remove devel.json file + ansible.builtin.file: + path: "/home/{{ username }}/.cache/paru/devel.json" + state: absent + +- name: Upgrade the system using paru, only act on AUR packages. + become: no + kewlfft.aur.aur: + upgrade: yes + aur_only: yes + +- name: Enable passwordless sudo for {{ username }} + lineinfile: + dest: /etc/sudoers + regexp: "^%wheel" + line: "{{ username }} ALL=(ALL) NOPASSWD: ALL" + validate: "/usr/sbin/visudo -cf %s"
A
tasks/reboot.yml
@@ -0,0 +1,2 @@
+- name: Unconditionally reboot the machine with all defaults + ansible.builtin.reboot: