Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
73a1a0ed64 | |||
48f3dee82f | |||
3b8eec9981 | |||
3230e28bc6 | |||
89758cb050 | |||
7fadae6fe6 | |||
294295fd41 | |||
773c4c8dd4 | |||
debd737d85 | |||
20f51f3aba | |||
31d6f096cf |
30
.drone.yml
30
.drone.yml
@ -51,33 +51,3 @@ steps:
|
|||||||
file_exists: skip
|
file_exists: skip
|
||||||
when:
|
when:
|
||||||
event: tag
|
event: tag
|
||||||
|
|
||||||
- name: repo_upload
|
|
||||||
image: appleboy/drone-scp
|
|
||||||
settings:
|
|
||||||
source: out/*.noarch.rpm
|
|
||||||
target: /vhosts/repo.libreschool.org/https/nethserver/7/devel/x86_64/Packages/
|
|
||||||
host: repo.libreschool.org
|
|
||||||
strip_components: 1
|
|
||||||
username:
|
|
||||||
from_secret: ssh_username
|
|
||||||
key:
|
|
||||||
from_secret: ssh_key
|
|
||||||
when:
|
|
||||||
event: tag
|
|
||||||
repo: LibreSchool/libreschool-client-manager
|
|
||||||
|
|
||||||
- name: repo_upload_srpms
|
|
||||||
image: appleboy/drone-scp
|
|
||||||
settings:
|
|
||||||
source: out/*.src.rpm
|
|
||||||
target: /vhosts/repo.libreschool.org/https/nethserver/7/devel/Source/SPackages/
|
|
||||||
host: repo.libreschool.org
|
|
||||||
strip_components: 1
|
|
||||||
username:
|
|
||||||
from_secret: ssh_username
|
|
||||||
key:
|
|
||||||
from_secret: ssh_key
|
|
||||||
when:
|
|
||||||
event: tag
|
|
||||||
repo: LibreSchool/libreschool-client-manager
|
|
||||||
|
47
README.md
47
README.md
@ -5,37 +5,82 @@ This software uses Ansible Playbooks to configure all connected clients.
|
|||||||
## Available Events
|
## Available Events
|
||||||
|
|
||||||
Adopt a machine (which should already exist in the *hosts* db):
|
Adopt a machine (which should already exist in the *hosts* db):
|
||||||
|
|
||||||
|
```bash
|
||||||
# signal-event client-adopt pc-99 username password
|
# signal-event client-adopt pc-99 username password
|
||||||
|
```
|
||||||
|
|
||||||
Reboot a machine:
|
Reboot a machine:
|
||||||
|
|
||||||
|
```bash
|
||||||
# signal-event client-reboot pc-01
|
# signal-event client-reboot pc-01
|
||||||
|
```
|
||||||
|
|
||||||
Reboot all machines:
|
Reboot all machines:
|
||||||
|
|
||||||
|
```bash
|
||||||
# signal-event client-reboot-all
|
# signal-event client-reboot-all
|
||||||
|
```
|
||||||
|
|
||||||
Force reconfiguration of a machine:
|
Force reconfiguration of a machine:
|
||||||
|
|
||||||
|
```bash
|
||||||
# signal-event client-reconfigure pc-02
|
# signal-event client-reconfigure pc-02
|
||||||
|
```
|
||||||
|
|
||||||
Force reconfiguration of all machines:
|
Force reconfiguration of all machines:
|
||||||
|
|
||||||
|
```bash
|
||||||
# signal-event client-reconfigure-all
|
# signal-event client-reconfigure-all
|
||||||
|
```
|
||||||
|
|
||||||
Shutdown a machine:
|
Shutdown a machine:
|
||||||
|
|
||||||
|
```bash
|
||||||
# signal-event client-shutdown pc-02
|
# signal-event client-shutdown pc-02
|
||||||
|
```
|
||||||
|
|
||||||
Shutdown all machines:
|
Shutdown all machines:
|
||||||
|
|
||||||
|
```bash
|
||||||
# signal-event client-shutdown-all
|
# signal-event client-shutdown-all
|
||||||
|
```
|
||||||
|
|
||||||
Update source configuration timestamp:
|
Update source configuration timestamp:
|
||||||
|
|
||||||
|
```bash
|
||||||
# signal-event client-update-lastconfig
|
# signal-event client-update-lastconfig
|
||||||
|
```
|
||||||
|
|
||||||
Wakeup a machine:
|
Wakeup a machine:
|
||||||
|
|
||||||
|
```bash
|
||||||
# signal-event client-wake pc-02
|
# signal-event client-wake pc-02
|
||||||
|
```
|
||||||
|
|
||||||
Wakeup all machines:
|
Wakeup all machines:
|
||||||
|
|
||||||
|
```bash
|
||||||
# signal-event client-wake-all
|
# signal-event client-wake-all
|
||||||
|
```
|
||||||
|
|
||||||
### Support for a group of machines
|
### Support for a group of machines
|
||||||
|
|
||||||
If you defined a group of machines, you can send signals to groups also.
|
If you defined a group of machines, you can send signals to groups also.
|
||||||
|
|
||||||
|
```bash
|
||||||
# db hosts set epoptes_lab1 group members 'pc-01 pc-02 pc-03' master pc-01
|
# db hosts set epoptes_lab1 group members 'pc-01 pc-02 pc-03' master pc-01
|
||||||
# signal-event client-wake epoptes_lab1
|
# signal-event client-wake epoptes_lab1
|
||||||
|
```
|
||||||
|
|
||||||
## E-smith DB reference
|
## E-smith DB reference
|
||||||
|
|
||||||
The general configuration is stored in the *client-manager* key. Properties of such key are:
|
The general configuration is stored in the *client-manager* key. Properties of such key are:
|
||||||
|
|
||||||
* *lastConfig*: timestamp of the actual configuration set
|
* *lastConfig*: timestamp of the actual configuration set
|
||||||
* *ManagementKeyFile*: management user's SSH public key
|
* *ManagementKeyFile*: management user's SSH public key
|
||||||
* *ManagementPrivateKeyFile*: management user's SSH private key
|
* *ManagementPrivateKeyFile*: management user's SSH private key
|
||||||
|
|
||||||
|
|
||||||
All host-specific information are stored in the *hosts* db. For each host we have:
|
All host-specific information are stored in the *hosts* db. For each host we have:
|
||||||
|
|
||||||
* *sshUser*: ssh user used to connect to the host. This is set when SSH adoption is successful
|
* *sshUser*: ssh user used to connect to the host. This is set when SSH adoption is successful
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
Summary: LibreSchool Client Manager
|
Summary: LibreSchool Client Manager
|
||||||
Name: libreschool-client-manager
|
Name: libreschool-client-manager
|
||||||
Version: 1.0
|
Version: 1.0.5
|
||||||
Release: 1.ns7
|
Release: 1.ns7
|
||||||
License: GPL
|
License: GPL
|
||||||
BuildArch: noarch
|
BuildArch: noarch
|
||||||
@ -47,7 +47,16 @@ mkdir -p %{buildroot}%{_localstatedir}/cache/client-manager
|
|||||||
%defattr(-,root,root)
|
%defattr(-,root,root)
|
||||||
|
|
||||||
%pre
|
%pre
|
||||||
/usr/bin/getent passwd amgmt || /usr/sbin/useradd -r -g wheel -d /home/amgmt -s /sbin/nologin amgmt
|
/usr/bin/getent passwd amgmt || /usr/sbin/useradd -r -m -g wheel -d /home/amgmt -s /sbin/nologin amgmt
|
||||||
|
if [ ! -d /home/amgmt/.ssh ] ; then
|
||||||
|
mkdir -p /home/amgmt/.ssh
|
||||||
|
fi
|
||||||
|
chmod 0700 /home/amgmt /home/amgmt/.ssh
|
||||||
|
chown -R amgmt:wheel /home/amgmt
|
||||||
|
if [ ! -f /home/amgmt/.ssh/id_rsa ] ; then
|
||||||
|
cat /dev/zero | sudo -u amgmt ssh-keygen -q -N ""
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$1" = 2 ]; then
|
if [ "$1" = 2 ]; then
|
||||||
#upgrade
|
#upgrade
|
||||||
/usr/bin/systemctl stop client-manager >/dev/null 2>&1 || :
|
/usr/bin/systemctl stop client-manager >/dev/null 2>&1 || :
|
||||||
@ -58,6 +67,7 @@ fi
|
|||||||
[ -e /usr/sbin/client-manager ] && [ ! -L /usr/sbin/client-manager ] && rm /usr/sbin/client-manager
|
[ -e /usr/sbin/client-manager ] && [ ! -L /usr/sbin/client-manager ] && rm /usr/sbin/client-manager
|
||||||
[ ! -L /usr/sbin/client-manager ] && ln -s httpd /usr/sbin/client-manager
|
[ ! -L /usr/sbin/client-manager ] && ln -s httpd /usr/sbin/client-manager
|
||||||
/sbin/e-smith/expand-template /etc/sudoers
|
/sbin/e-smith/expand-template /etc/sudoers
|
||||||
|
[ ! -d /etc/httpd/client-manager ] && mkdir /etc/httpd/client-manager
|
||||||
/sbin/e-smith/expand-template /etc/httpd/client-manager/httpd.conf
|
/sbin/e-smith/expand-template /etc/httpd/client-manager/httpd.conf
|
||||||
/sbin/e-smith/expand-template /etc/ansible/reconfigure_clients.yml
|
/sbin/e-smith/expand-template /etc/ansible/reconfigure_clients.yml
|
||||||
/sbin/e-smith/signal-event runlevel-adjust
|
/sbin/e-smith/signal-event runlevel-adjust
|
||||||
@ -87,5 +97,24 @@ if [ "$1" = 0 ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
* Sun Apr 28 2019 Paolo Asperti <paolo@asperti.com> - 1.0-1.ns7
|
* Sun Apr 5 2020 Paolo Asperti <paolo@asperti.com> - 1.0.5-1.ns7
|
||||||
|
- playbook split + added ntp
|
||||||
|
|
||||||
|
* Thu Apr 2 2020 Paolo Asperti <paolo@asperti.com> - 1.0.4-1.ns7
|
||||||
|
- per-host log files
|
||||||
|
|
||||||
|
* Sun Mar 8 2020 Paolo Asperti <paolo@asperti.com> - 1.0.3-1.ns7
|
||||||
|
- fix re-adoption
|
||||||
|
|
||||||
|
* Sat Mar 7 2020 Paolo Asperti <paolo@asperti.com> - 1.0.2-1.ns7
|
||||||
|
- fix re-adoption
|
||||||
|
- added some required packages
|
||||||
|
- updated readme
|
||||||
|
|
||||||
|
* Sun Mar 1 2020 Paolo Asperti <paolo@asperti.com> - 1.0.1-1.ns7
|
||||||
|
- added client shell
|
||||||
|
- fixed amgmt user creation
|
||||||
|
- fix creation of httpd config
|
||||||
|
|
||||||
|
* Sun Apr 28 2019 Paolo Asperti <paolo@asperti.com> - 1.0.0-1.ns7
|
||||||
- First release for NethServer 7
|
- First release for NethServer 7
|
||||||
|
@ -5,6 +5,8 @@ remote_user = amgmt
|
|||||||
private_key_file=/home/amgmt/.ssh/id_rsa
|
private_key_file=/home/amgmt/.ssh/id_rsa
|
||||||
nocows = 1
|
nocows = 1
|
||||||
log_path = /var/log/ansible.log
|
log_path = /var/log/ansible.log
|
||||||
|
bin_ansible_callbacks = yes
|
||||||
|
stdout_callback = log_plays
|
||||||
|
|
||||||
[privilege_escalation]
|
[privilege_escalation]
|
||||||
become=True
|
become=True
|
||||||
|
4
root/etc/ansible/roles/common/handlers/main.yml
Normal file
4
root/etc/ansible/roles/common/handlers/main.yml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
- name: restart systemd-timesyncd
|
||||||
|
service: name=systemd-timesyncd state=restarted
|
||||||
|
|
16
root/etc/ansible/roles/common/tasks/libreschool_repo.yml
Normal file
16
root/etc/ansible/roles/common/tasks/libreschool_repo.yml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: Add LibreSchool signing key
|
||||||
|
apt_key:
|
||||||
|
url: http://repo.libreschool.org/libreschool.asc
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: Add LibreSchool repository
|
||||||
|
apt_repository:
|
||||||
|
repo: deb http://repo.libreschool.org/ubuntu {{ ansible_distribution_release }} main
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: Update repositories cache and install "libreschool-client" package
|
||||||
|
apt:
|
||||||
|
name: libreschool-client
|
||||||
|
update_cache: yes
|
@ -5,17 +5,8 @@
|
|||||||
register: esmith
|
register: esmith
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
|
||||||
- name: Add LibreSchool signing key
|
- include: libreschool_repo.yml
|
||||||
apt_key:
|
|
||||||
url: http://repo.libreschool.org/libreschool.asc
|
|
||||||
state: present
|
|
||||||
|
|
||||||
- name: Add LibreSchool repository
|
- include: required_packages.yml
|
||||||
apt_repository:
|
|
||||||
repo: deb http://repo.libreschool.org/ubuntu {{ ansible_distribution_release }} main
|
|
||||||
state: present
|
|
||||||
|
|
||||||
- name: Update repositories cache and install "libreschool-client" package
|
- include: ntp.yml
|
||||||
apt:
|
|
||||||
name: libreschool-client
|
|
||||||
update_cache: yes
|
|
||||||
|
26
root/etc/ansible/roles/common/tasks/ntp.yml
Normal file
26
root/etc/ansible/roles/common/tasks/ntp.yml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
# TODO: check for other distro, maybe we should first check if we have systemd,
|
||||||
|
# and if so, we have to properly configure it. If we don't have systemd,
|
||||||
|
# we have to install and configure ntpd
|
||||||
|
|
||||||
|
- name: Remove NTP package as we use systemd
|
||||||
|
apt:
|
||||||
|
name: [ 'ntp' ]
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
- name: Setup NTP server
|
||||||
|
ini_file:
|
||||||
|
path: /etc/systemd/timesyncd.conf
|
||||||
|
section: Time
|
||||||
|
option: NTP
|
||||||
|
value: "{{ esmith.SystemName }}.{{ esmith.DomainName }}"
|
||||||
|
notify: restart systemd-timesyncd
|
||||||
|
|
||||||
|
- name: Setup Fallback NTP server
|
||||||
|
ini_file:
|
||||||
|
path: /etc/systemd/timesyncd.conf
|
||||||
|
section: Time
|
||||||
|
option: FallbackNTP
|
||||||
|
value: pool.ntp.org
|
||||||
|
notify: restart systemd-timesyncd
|
@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: Installing common required packages
|
||||||
|
apt:
|
||||||
|
name: [ 'debconf', 'debconf-utils' ]
|
||||||
|
state: latest
|
||||||
|
|
@ -13,7 +13,6 @@
|
|||||||
section: server
|
section: server
|
||||||
no_extra_spaces: yes
|
no_extra_spaces: yes
|
||||||
value: "{{ configuration_timestamp }}"
|
value: "{{ configuration_timestamp }}"
|
||||||
|
changed_when: no
|
||||||
notify: rerun-libreschool-client
|
notify: rerun-libreschool-client
|
||||||
when: lsclient_installed.rc == 0
|
when: lsclient_installed.rc == 0
|
||||||
|
|
||||||
# TODO: ini_file always return "changed" even if it's not
|
|
||||||
|
@ -17,6 +17,8 @@ ping -c1 "$HOST" >/dev/null || (
|
|||||||
exit 1
|
exit 1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
ssh-keygen -R "${HOST}"
|
||||||
|
|
||||||
sshpass -p "${PASS}" ssh -t -o StrictHostKeyChecking=no "${USER}@${HOST}" "whoami" || (
|
sshpass -p "${PASS}" ssh -t -o StrictHostKeyChecking=no "${USER}@${HOST}" "whoami" || (
|
||||||
echo "Can't login to $HOST as $USER"
|
echo "Can't login to $HOST as $USER"
|
||||||
exit 1
|
exit 1
|
||||||
|
17
root/usr/bin/client-shell
Executable file
17
root/usr/bin/client-shell
Executable file
@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
if [ "$1" = "" ] ; then
|
||||||
|
echo "Usage:"
|
||||||
|
echo "$0 [hostname]"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
USER=$(db hosts getprop "$1" sshUser)
|
||||||
|
|
||||||
|
if [ "$USER" = "" ] ; then
|
||||||
|
echo "Can't find an user for $1"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
/usr/bin/sudo -u amgmt ssh-keygen -R "${1}"
|
||||||
|
/usr/bin/sudo -u amgmt /usr/bin/ssh -o StrictHostKeyChecking=no ${USER}\@${1} ${@:2}
|
Loading…
x
Reference in New Issue
Block a user