Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

start of server attributes check #19

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ New roles should be developed on branches, and changes rolled out to all servers
- `nrpe`
- `cron-mail-redirect`
- `unattended-upgrades`
- `server-attributes`
- `pxe`
- `dnsmasq`
- `ipxe`
Expand Down
2 changes: 2 additions & 0 deletions playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
tags: unattended-upgrades
- role: cron-mail-redirect
tags: cron-mail-redirect
- role: server-attributes
tags: server-attributes
tags: common
- hosts: device_roles_Router
roles:
Expand Down
23 changes: 23 additions & 0 deletions roles/server-attributes/files/attributes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/python3
import json
import subprocess

data = {}

with open("/etc/os-release", "r") as fh:
for line in fh:
k, v = line.split("=", 1)
v = v.strip().strip("\"")
if k == "ID":
data["distro"] = v
elif k == "VERSION_ID":
data["version"] = v

# some of our servers don't support iproute2 json output
# just send back a None
try:
data["network"] = json.loads(subprocess.check_output(["ip", "-details", "-json", "addr"]))
except:
data["network"] = None

print(json.dumps(data))
1 change: 1 addition & 0 deletions roles/server-attributes/files/netbox.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC0pNFstmYWf7cWHRKdZd10W0EHM9Mg+Ab1no61930dK5wbcJ6Axjg+buFpMdv8ghrpFI5lITGlExoGQSWcg27MqgUNPlZddfMK57qOtcj7UumyFBji2cKrr5qnZ7NB5Mp6ZFuCXzGwG7uEPdrnJuVYg+ZE8gzneH3pftx2OFsDw4WXOS5d3plUlGB8tLr8meIfOM+Jb1yQcyT1/nFQHmYs4LmZjFO/I9/VzC1+AaPLaDLVxAf5y3ZxGGZHDzA0iGxhZPFpPh1SGots8V2MwPtcI0Ok+PsoeOPhG8Trv7FCNYDzovWf2auW9iQbiaFNmtTRNAgNA8Yx2ev8vIOAJLan netbox@netbox
15 changes: 15 additions & 0 deletions roles/server-attributes/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
- name: add attributes script dir
file:
path: /opt/sown/server-attributes/
state: directory
- name: add netbox key
authorized_key:
user: root
state: present
key: "{{ lookup('file', 'netbox.pub') }}"
key_options: 'restrict,command="/opt/sown/server-attributes/attributes.py"'
- name: add attributes script
copy:
src: attributes.py
dest: /opt/sown/server-attributes/attributes.py
mode: "700"