From 7008a8fcd447bf733b746aac73246fb6007936c7 Mon Sep 17 00:00:00 2001 From: Blallo Date: Tue, 23 Feb 2021 18:47:25 +0100 Subject: [PATCH] Init --- .vagrant/bundler/global.sol | 1 + .../debiantest/libvirt/action_provision | 1 + .vagrant/machines/debiantest/libvirt/box_meta | 1 + .../machines/debiantest/libvirt/creator_uid | 1 + .vagrant/machines/debiantest/libvirt/id | 1 + .../machines/debiantest/libvirt/index_uuid | 1 + .../debiantest/libvirt/synced_folders | 1 + .../machines/debiantest/libvirt/vagrant_cwd | 1 + .vagrant/rgloader/loader.rb | 9 +++ Vagrantfile | 31 ++++++++ ansible.cfg | 3 + handlers/main.yml | 5 ++ inventory | 1 + playbook.yml | 8 ++ tasks/main.yml | 75 +++++++++++++++++++ test_vars.yml | 6 ++ 16 files changed, 146 insertions(+) create mode 100644 .vagrant/bundler/global.sol create mode 100644 .vagrant/machines/debiantest/libvirt/action_provision create mode 100644 .vagrant/machines/debiantest/libvirt/box_meta create mode 100644 .vagrant/machines/debiantest/libvirt/creator_uid create mode 100644 .vagrant/machines/debiantest/libvirt/id create mode 100644 .vagrant/machines/debiantest/libvirt/index_uuid create mode 100644 .vagrant/machines/debiantest/libvirt/synced_folders create mode 100644 .vagrant/machines/debiantest/libvirt/vagrant_cwd create mode 100644 .vagrant/rgloader/loader.rb create mode 100644 Vagrantfile create mode 100644 ansible.cfg create mode 100644 handlers/main.yml create mode 100644 inventory create mode 100644 playbook.yml create mode 100644 tasks/main.yml create mode 100644 test_vars.yml diff --git a/.vagrant/bundler/global.sol b/.vagrant/bundler/global.sol new file mode 100644 index 0000000..384aa1f --- /dev/null +++ b/.vagrant/bundler/global.sol @@ -0,0 +1 @@ +{"dependencies":[["formatador",["~> 0.2"]],["excon",["~> 0.49"]],["builder",[">= 0"]],["fog-core",["~> 1.43.0"]],["mini_portile2",["~> 2.4.0"]],["nokogiri",[">= 1.6.0"]],["json",[">= 0"]],["ruby-libvirt",[">= 0.7.0"]],["fog-xml",["~> 0.1.1"]],["multi_json",["~> 1.10"]],["fog-json",[">= 0"]],["fog-libvirt",[">= 0.3.0"]],["vagrant-libvirt",["= 0.0.45"]]],"checksum":"fffd3c92382f68b8c2b567be0284154ab699575030b9530f4eb9eaf340d61e70","vagrant_version":"2.2.9"} \ No newline at end of file diff --git a/.vagrant/machines/debiantest/libvirt/action_provision b/.vagrant/machines/debiantest/libvirt/action_provision new file mode 100644 index 0000000..4c63c40 --- /dev/null +++ b/.vagrant/machines/debiantest/libvirt/action_provision @@ -0,0 +1 @@ +1.5:4a7308aa-0f0c-4650-960a-ab46a2f323a9 \ No newline at end of file diff --git a/.vagrant/machines/debiantest/libvirt/box_meta b/.vagrant/machines/debiantest/libvirt/box_meta new file mode 100644 index 0000000..cbca31b --- /dev/null +++ b/.vagrant/machines/debiantest/libvirt/box_meta @@ -0,0 +1 @@ +{"name":"debian/buster64","version":"10.4.0","provider":"libvirt","directory":"boxes/debian-VAGRANTSLASH-buster64/10.4.0/libvirt"} \ No newline at end of file diff --git a/.vagrant/machines/debiantest/libvirt/creator_uid b/.vagrant/machines/debiantest/libvirt/creator_uid new file mode 100644 index 0000000..e37d32a --- /dev/null +++ b/.vagrant/machines/debiantest/libvirt/creator_uid @@ -0,0 +1 @@ +1000 \ No newline at end of file diff --git a/.vagrant/machines/debiantest/libvirt/id b/.vagrant/machines/debiantest/libvirt/id new file mode 100644 index 0000000..ddb73a7 --- /dev/null +++ b/.vagrant/machines/debiantest/libvirt/id @@ -0,0 +1 @@ +4a7308aa-0f0c-4650-960a-ab46a2f323a9 \ No newline at end of file diff --git a/.vagrant/machines/debiantest/libvirt/index_uuid b/.vagrant/machines/debiantest/libvirt/index_uuid new file mode 100644 index 0000000..aed14e1 --- /dev/null +++ b/.vagrant/machines/debiantest/libvirt/index_uuid @@ -0,0 +1 @@ +1581929e88a845b69398f3a365a435c9 \ No newline at end of file diff --git a/.vagrant/machines/debiantest/libvirt/synced_folders b/.vagrant/machines/debiantest/libvirt/synced_folders new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/.vagrant/machines/debiantest/libvirt/synced_folders @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/.vagrant/machines/debiantest/libvirt/vagrant_cwd b/.vagrant/machines/debiantest/libvirt/vagrant_cwd new file mode 100644 index 0000000..2bba838 --- /dev/null +++ b/.vagrant/machines/debiantest/libvirt/vagrant_cwd @@ -0,0 +1 @@ +/home/leo/Documents/coding/playbooks/debian_toolbox/roles/syncthing \ No newline at end of file diff --git a/.vagrant/rgloader/loader.rb b/.vagrant/rgloader/loader.rb new file mode 100644 index 0000000..c3c05b0 --- /dev/null +++ b/.vagrant/rgloader/loader.rb @@ -0,0 +1,9 @@ +# This file loads the proper rgloader/loader.rb file that comes packaged +# with Vagrant so that encoded files can properly run with Vagrant. + +if ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"] + require File.expand_path( + "rgloader/loader", ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"]) +else + raise "Encoded files can't be read outside of the Vagrant installer." +end diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..131b0ac --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,31 @@ +# This guide is optimized for Vagrant 1.7 and above. +# Although versions 1.6.x should behave very similarly, it is recommended +# to upgrade instead of disabling the requirement below. +Vagrant.require_version ">= 1.7.0" + +Vagrant.configure(2) do |config| + + config.vm.box = "debian/buster64" + + config.vm.define "debiantest" do |m| + m.vm.hostname = "debiantest" + m.vm.network :private_network, ip: "192.168.123.2", libvirt__dhcp_enabled: false + m.vm.synced_folder ".", "/vagrant", disabled: true + end + # Disable the new default behavior introduced in Vagrant 1.7, to + # ensure that all Vagrant machines will use the same SSH key pair. + # See https://github.com/mitchellh/vagrant/issues/5005 + config.ssh.insert_key = false + + config.vm.provider :libvirt do |lv| + lv.cpus = 2 + lv.memory = 1024 + end + + config.vm.provision "ansible" do |ansible| + ansible.become = true + ansible.verbose = "v" + ansible.playbook = "playbook.yml" + ansible.inventory_path = "inventory" + end +end diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..1628b8c --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,3 @@ +[defaults] +roles_path = ../ +ansible_python_interpreter = /usr/bin/python3 diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..193fdbb --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,5 @@ +--- +- name: restart syncthing + systemd: + state: restarted + name: syncthing@syncthing.service diff --git a/inventory b/inventory new file mode 100644 index 0000000..edb98dc --- /dev/null +++ b/inventory @@ -0,0 +1 @@ +debiantest diff --git a/playbook.yml b/playbook.yml new file mode 100644 index 0000000..e5be6ae --- /dev/null +++ b/playbook.yml @@ -0,0 +1,8 @@ +--- +- hosts: debiantest + gather_facts: yes + vars_files: + - ./test_vars.yml + + roles: + - syncthing diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..4fad376 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,75 @@ +--- +- name: Ensure syncthing user is present + user: + name: syncthing + state: present + create_home: yes + home: "{{ syncthing.home }}" + shell: /usr/sbin/nologin + +- name: Ensure syncthing dir is present + file: + path: "{{ syncthing.dir }}" + state: directory + owner: syncthing + group: syncthing + mode: 0700 + +- name: Ensure syncthing is installed + apt: + name: + - syncthing + - python-lxml + - python3-lxml + state: latest + +- name: Ensure syncthing is running + systemd: + name: syncthing@syncthing.service + state: started + enabled: yes + +- name: Set the sync directory + xml: + path: "{{ syncthing.home }}/.config/syncthing/config.xml" + xpath: /configuration/folder + attribute: path + value: "{{ syncthing.dir }}" + notify: restart syncthing + retries: 3 + delay: 3 + register: result + until: not result.failed + +- name: Add an user to log into the interface + xml: + path: "{{ syncthing.home }}/.config/syncthing/config.xml" + xpath: /configuration/gui/user + value: "{{ syncthing.user }}" + notify: restart syncthing + retries: 3 + delay: 3 + register: result + until: not result.failed + +- name: Set the password + xml: + path: "{{ syncthing.home }}/.config/syncthing/config.xml" + xpath: /configuration/gui/password + value: "{{ syncthing.password }}" + notify: restart syncthing + retries: 3 + delay: 3 + register: result + until: not result.failed + +- name: Make public the management interface + xml: + path: "{{ syncthing.home }}/.config/syncthing/config.xml" + xpath: /configuration/gui/address + value: 0.0.0.0:8384 + notify: restart syncthing + retries: 3 + delay: 3 + register: result + until: not result.failed diff --git a/test_vars.yml b/test_vars.yml new file mode 100644 index 0000000..a3f1eb6 --- /dev/null +++ b/test_vars.yml @@ -0,0 +1,6 @@ +--- +syncthing: + dir: /syncthing + home: /var/syncthing + user: testuser + password: $6$ZFrzgBIbv/QuQz1S$QjorAV4gEyUHNO.PthWAe9utbNAd4vogAgLJTXuAt8bmK7.bc5za5kXKPLy.VFSuRtp9DVljRFhZm1LpV.c9Y0 # this is: password