Commit 4242c112 by Alain Takoudjou

Merge branch 'logging' into 'master'

Logging

Bug fix and improvment in Ansile vm-bootstrap playbook

See merge request !15
2 parents 54675ce6 58a54ecd
#!/usr/bin/python
import os
import sys
if __name__ == "__main__":
if len(sys.argv) < 4:
print "Use: %s FILE1 FILE2 DEST_FILE" % sys.argv[0]
exit(1)
file1 = sys.argv[1]
file2 = sys.argv[2]
dest = sys.argv[3]
lines = lines_cmp = []
notfound = []
with open(file1, 'r') as ff:
lines = ff.readlines()
with open(file2, 'r') as ff2:
lines_cmp = ff2.read()
for line in lines:
if not line in lines_cmp:
notfound.append(line)
with open(dest, 'w') as f:
f.write('\n'.join(notfound))
- include: uploadlog.yml
- include: rerun.yml
- name: set dirty ratio
sysctl: name="vm.dirty_ratio" value=10 sysctl_set=yes state=present reload=yes
- name: set dirty background ratio
sysctl: name="vm.dirty_background_ratio" value=5 sysctl_set=yes state=present reload=yes
- name: Create /etc/opt dir
file: dest=/etc/opt mode=775 state=directory
......@@ -27,4 +32,4 @@
- include: hostname.yml
- include: user.yml
- include: sudo.yml
- include: ssh.yml
- include: ssh.yml
\ No newline at end of file
......@@ -6,6 +6,7 @@
cron: name="Update vm bootstrap"
minute="*/12"
job="bash -lc /usr/local/bin/vm-bootstrap-update >> /var/log/vm-bootstrap.log"
cron_file=ansible-vm-bootstrap user="root"
- name: Check if /opt/slapos.playbook already exists
file: path=/opt/slapos.playbook/ state=directory
......
......@@ -6,19 +6,43 @@
file: path=/home/netadmin/.ssh state=directory mode=700 owner=netadmin group=netadmin
- name: Download ssh authorized keys
get_url: url=http://10.0.2.100/authorized_keys dest=/root/.ssh/authorized_keys.download mode=755
get_url: url=http://10.0.2.100/authorized_keys dest=/etc/opt/authorized_keys mode=644 force=yes
ignore_errors: True
- name: stat /root/.ssh/authorized_keys.download
stat: path=/root/.ssh/authorized_keys.download
- name: stat /etc/opt/authorized_keys
stat: path=/etc/opt/authorized_keys
register: authorized_keys
- name: replace /root/.ssh/authorized_keys
copy: src=/root/.ssh/authorized_keys.download dest=/root/.ssh/authorized_keys mode=644
- name: stat /etc/opt/authorized_keys.old
stat: path=/etc/opt/authorized_keys.old
register: authorized_keys_old
- name: get removed keys
script: file_cmp /etc/opt/authorized_keys.old /etc/opt/authorized_keys /etc/opt/authorized_keys_deleted
when: authorized_keys.stat.exists == True and authorized_keys_old.stat.exists == True
- name: stat /etc/opt/authorized_keys_deleted
stat: path=/etc/opt/authorized_keys_deleted
register: authorized_keys_deleted
- name: Remove deleted authorized_keys
authorized_key: user=netadmin key="{{ lookup('file', '/etc/opt/authorized_keys_deleted') }}" state=absent
when: authorized_keys_deleted.stat.exists == True
- name: Remove deleted authorized_keys for root
authorized_key: user=root key="{{ lookup('file', '/etc/opt/authorized_keys_deleted') }}" state=absent
when: authorized_keys_deleted.stat.exists == True
- name: save these authorized_keys
copy: src=/etc/opt/authorized_keys dest=/etc/opt/authorized_keys.old mode=644 force=yes
when: authorized_keys.stat.exists == True
- name: Add netadmin authorized keys
authorized_key: user=netadmin key="{{ lookup('file', '/etc/opt/authorized_keys') }}"
when: authorized_keys.stat.exists == True
- name: replace /home/netadmin/.ssh/authorized_keys
copy: src=/root/.ssh/authorized_keys.download dest=/home/netadmin/.ssh/authorized_keys mode=644 owner=netadmin group=netadmin
- name: Add root authorized keys
authorized_key: user=root key="{{ lookup('file', '/etc/opt/authorized_keys') }}"
when: authorized_keys.stat.exists == True
- name: update /etc/ssh/sshd_config
......
......@@ -6,4 +6,4 @@
cron: name="Upload ansible files to http server"
minute="*/7"
job="/usr/local/bin/ansible-upload-vm-logs http://10.0.2.100/ /var/log/vm-bootstrap.log > /var/log/ansible-upload.log"
cron_file=ansible-upload-log user="root"
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!