-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.yml
103 lines (87 loc) · 3.34 KB
/
setup.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
---
- hosts: all
any_errors_fatal: true
vars:
- my_user: "{{ myuser }}"
- pwd_alias: "{{ lookup('password', '/dev/null length=15 chars=ascii_letters') }}"
tasks:
- set_fact:
my_pass: "{{ pwd_alias }}"
- name: Display Host info
vars:
msg: |
Host: {{ ansible_fqdn }}
IP: {{ ansible_default_ipv4['address'] }}
OS: {{ ansible_distribution }} {{ ansible_distribution_major_version }}
Kernel: {{ ansible_kernel_version }}
debug:
msg: "{{ msg.split('\n') }}"
- name: Check network connectivity
wait_for:
host: github.com
port: 22
state: started
delay: 0
timeout: 5
- name: Check if initial setup has already been performed
stat: path="/root/.init_setup_done"
register: already_prep
- name: Fail if already run on host
fail: msg="Initial Setup Already completed!"
when: already_prep.stat.exists
- name: "Update cache and execute dist-upgrade"
apt:
update_cache: yes
upgrade: dist
#cache_valid_time: 3600 -- We need to update the cache every time, if no enterprise key installed we should recive an Unauthorized message
- name: Install utils (vim, screen, unzip, nethogs, iftop, htop)
package:
name:
- vim
- screen
- unzip
- nethogs
- iftop
- htop
state: latest
- name: Creating .screenrc file
copy:
dest: "/root/.screenrc"
content: "startup_message off"
- name: Install cv4pve-autosnap by Corsinvest - https://github.com/Corsinvest/cv4pve-autosnap
unarchive:
src: "https://github.com/Corsinvest/cv4pve-autosnap/releases/download/v1.14.10/cv4pve-autosnap-linux-x64.zip"
dest: /usr/local/bin
remote_src: yes
mode: 0755
owner: root
group: root
- name: Generating cron for auto-snapshot
ansible.builtin.cron:
name: proxmox autosnap
minute: "55"
hour: "20"
user: root
#job: /usr/local/bin/cv4pve-autosnap --host=localhost --username="userbackup@pve" --password="mypassword" --vmid="all" snap --label="daily" --keep=4 >> /tmp/px-autosnap.log
job: /usr/local/bin/cv4pve-autosnap --host=localhost --username="{{ my_user}}@pve" --password="{{my_pass}}" --vmid="all" snap --label="daily" --keep=4 >> /tmp/px-autosnap.log
cron_file: 10-autosnap-px
- name: Create {{ my_user }} user
shell: pveum user add {{ my_user }}@pve --password {{ my_pass }} --comment "Ansible added admin"
- name: Create adminz group
shell: pveum group add adminz -comment "Ansible Admins"
- name: Give Administrator permission to adminz group
shell: pveum acl modify / -group adminz -role Administrator
- name: Add {{ my_user }}@pve to adminz group
shell: pveum user modify "{{ my_user }}"@pve -group adminz
- name: Create lock file
file: path="/root/.init_setup_done" state=touch
- name: Done!
vars:
msg: |
An additional user has been create with Administrator privileges.
Username : {{ my_user }}
Password : {{ my_pass }}
A new cron file has been generated to automate the daily vm snapshot
located at : /etc/cron.d/10-autosnap-px
debug:
msg: "{{ msg.split('\n') }}"