first commit
This commit is contained in:
20
internal/space_creator/static/dd.datetime.sh
Normal file
20
internal/space_creator/static/dd.datetime.sh
Normal file
@@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
# vi: set tabstop=4 shiftwidth=4 noexpandtab :
|
||||
#------------------------------------------------#
|
||||
# Модуль получения текущего даты-времени.
|
||||
#
|
||||
# . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
# - dd.datetime:
|
||||
# register: current_datetime
|
||||
#------------------------------------------------#
|
||||
source $1
|
||||
set -euo pipefail
|
||||
L_CHANGED=false
|
||||
|
||||
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
|
||||
|
||||
__curr_date=$(date +%Y%m%d_%H%M%S)
|
||||
|
||||
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
|
||||
|
||||
echo "{ \"changed\": ${L_CHANGED}, \"datetime\": \"$__curr_date\" }"
|
||||
28
internal/space_creator/static/dd.restore.sh
Normal file
28
internal/space_creator/static/dd.restore.sh
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
# vi: set tabstop=4 shiftwidth=4 noexpandtab :
|
||||
#------------------------------------------------#
|
||||
# Модуль получения даты последнего бэкапа, если
|
||||
# в качесте даты указано "latest". Иначе,
|
||||
# возвращает переданный параметр.
|
||||
#
|
||||
# . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
# - dd.restore:
|
||||
# role_path: "{{ role_path }}"
|
||||
# inventory: name_of_inventory
|
||||
# datetime: 20240412_231753
|
||||
# register: res_dd_restore
|
||||
#------------------------------------------------#
|
||||
source $1
|
||||
set -euo pipefail
|
||||
L_CHANGED=false
|
||||
|
||||
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
|
||||
|
||||
if [[ "$datetime" == "latest" ]]; then
|
||||
cd "$role_path/backups/$inventory"
|
||||
datetime=$(ls -1t | head -1)
|
||||
fi
|
||||
|
||||
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
|
||||
|
||||
echo "{ \"changed\": $L_CHANGED, \"inventory\": \"$inventory\", \"datetime\": \"$datetime\" }"
|
||||
63
internal/space_creator/static/dd.sethostname.sh
Normal file
63
internal/space_creator/static/dd.sethostname.sh
Normal file
@@ -0,0 +1,63 @@
|
||||
#!/bin/bash
|
||||
# vi: set tabstop=4 shiftwidth=4 noexpandtab :
|
||||
#------------------------------------------------#
|
||||
# Модуль настройки hostname.
|
||||
#
|
||||
# В отличии от стокового модуля "hostname",
|
||||
# данный модуль так же патчит файл `/etc/hosts`.
|
||||
# . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
# - dd.sethostname:
|
||||
# name: my-virtual-machine
|
||||
#------------------------------------------------#
|
||||
source $1
|
||||
set -euo pipefail
|
||||
|
||||
__curr_hostname="$(hostname)"
|
||||
__changed=false
|
||||
|
||||
if [[ "$__curr_hostname" != "$name" ]]; then
|
||||
hostnamectl set-hostname "$name"
|
||||
perl - "$__curr_hostname" "$name" <<'EOP'
|
||||
#!perl
|
||||
use strict;
|
||||
use warnings;
|
||||
use Data::Dumper qw(Dumper);
|
||||
|
||||
my ($oldhost, $newhost) = @ARGV;
|
||||
my %hosts;
|
||||
|
||||
open(FILE_HOSTS, "<", "/etc/hosts") || die $!;
|
||||
while(<FILE_HOSTS>) {
|
||||
chomp;
|
||||
if (/^#/ || /^\s*$/) {
|
||||
next;
|
||||
}
|
||||
my @pair = split(/\s+/, $_, 2);
|
||||
my @values = split(/\s+/, $pair[1]);
|
||||
$hosts{$pair[0]} = [@values];
|
||||
}
|
||||
close(FILE_HOSTS);
|
||||
|
||||
while (my ($key, $value) = each(%hosts)) {
|
||||
my $i = 0;
|
||||
foreach my $host (@{ $value }) {
|
||||
if ($host eq $oldhost) {
|
||||
@{ $value }[$i] = $newhost;
|
||||
$hosts{$key} = [@{ $value }[$i]];
|
||||
}
|
||||
$i = $i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
open(FILE_HOSTS, ">", "/etc/hosts") || die $!;
|
||||
foreach my $key (sort(keys(%hosts))) {
|
||||
print FILE_HOSTS "$key @{$hosts{$key}}\n";
|
||||
}
|
||||
close(FILE_HOSTS);
|
||||
EOP
|
||||
__changed=true
|
||||
fi
|
||||
|
||||
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
|
||||
|
||||
echo "{ \"changed\": $__changed }"
|
||||
15
internal/space_creator/static/editorconfig.txt
Normal file
15
internal/space_creator/static/editorconfig.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
root = true
|
||||
|
||||
[*.{sh,yml}]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
|
||||
[*.sh]
|
||||
indent_size = 4
|
||||
max_line_length = 80
|
||||
|
||||
[*.yml]
|
||||
indent_size = 2
|
||||
max_line_length = 80
|
||||
5
internal/space_creator/static/gitignore.txt
Normal file
5
internal/space_creator/static/gitignore.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
# Jet Brains IDEA
|
||||
/.idea/
|
||||
|
||||
# Other
|
||||
*.bak
|
||||
Reference in New Issue
Block a user