MoinMoin automation is here, pray CransBot
parent
8859721873
commit
22f4fbd71f
9
base.yml
9
base.yml
|
@ -37,6 +37,15 @@
|
|||
roles:
|
||||
- ldap-client
|
||||
|
||||
# Document servers
|
||||
- hosts: voyager.adm.crans.org # test only on voyager for now
|
||||
vars:
|
||||
moinmoin_user: "{{ vault_moinmoin_user }}"
|
||||
moinmoin_password: "{{ vault_moinmoin_password }}"
|
||||
moinmoin_base_url: https://wiki.crans.org/CransTechnique/LesServeurs
|
||||
roles:
|
||||
- moinmoin-server
|
||||
|
||||
# Deploy LDAP replica
|
||||
- hosts: odlyd.adm.crans.org,soyouz.adm.crans.org,fy.adm.crans.org,thot.adm.crans.org
|
||||
roles: [] # TODO
|
||||
|
|
|
@ -1,34 +1,40 @@
|
|||
$ANSIBLE_VAULT;1.1;AES256
|
||||
63636535353833663737346463323366633264356662383235363231613431363038646435343830
|
||||
3836363934663864356666366161353231343033353665610a636230343963386538336635376361
|
||||
38333931393362353463383939666230393361613466666236666532613161323839633838383132
|
||||
3638356236663536300a373833303062653534346161613634393661363638363963316463626539
|
||||
30393564633462363831623234313961656661646635303435316338336566623962353539656631
|
||||
35623465313036653832613565656161303633376531346337316436366435633461383733316530
|
||||
61333262353935323732646239366161346634616233613166306430386537346632333030626335
|
||||
34326239666461613530663466303239373466373631643962313731653136393361633963383566
|
||||
32363532323437333862623466373734663561383637326537323464383334303337323861333862
|
||||
63366631346461393732633038383438383039353763306365313666393730633836653965643537
|
||||
65373362303631646630366439633464356635616533366563633764356564333538373638363964
|
||||
31613230643138313738383661376363313739336463353838653162306336343534343464396330
|
||||
39353336633430373361356366323330393739303234383935616530326264393464336433363865
|
||||
39306666636137343764333466343063373263326239303139666362373332393934303235613366
|
||||
32373331333232376332613931333133363536313163366536633539306464616137666561313863
|
||||
35656430663461353464376335396465303634393835303935393062373366303664663838373734
|
||||
36623435636535393561323735366564306464646532323139616237656530353436356635373366
|
||||
61396464626432653731323138643462306432353932313263346561663336313066396162323230
|
||||
30623561393665336634353364376138666533666235316137353238383235313261303235663534
|
||||
64623963653633306339643866646638633465663433336239383264393463373739393235636337
|
||||
61313838666466373561363065636635623835623239316132623565613532333364313863363234
|
||||
63616465633966336164306566646265613563643631363038343231373861643737323533646432
|
||||
62316631333763393463353963383761356333326231616131353063653064306264623235616534
|
||||
34626266313737363161653039663832613336626465333566616266366536613532623935323933
|
||||
66396437326561663564633261646538613733623632336234656663633935376562346237373732
|
||||
32643764313966333130316137346566396636343836623266333231383336393564326663343530
|
||||
39333961333639346437623030313930333062646265363737613632333537636632396164613132
|
||||
36623039313663643962663963643231396235656536373835386264336161633738633863656132
|
||||
38386538336439316230646531653064366535616536643264316634616265346638666333633661
|
||||
65303531643133323464616661656134346337643135313833623763363466653965356664363332
|
||||
30316563613739363834306236363162623562343237303737333964353632653062343634643234
|
||||
61306336343832393866353136303837613766636335663033616437636531393363636261323566
|
||||
6562
|
||||
37373933363563303566623732633165343839663164663535316638633462626636326135316534
|
||||
3839346634623331363336663863353363376665613764390a383866613635363238323637386235
|
||||
61623963366463636561346162616532626133306165343161393333616363656339643933393531
|
||||
6662343239653361320a633064306238363836346166653931356334376537636266646237323438
|
||||
65316261636463336261643831653661383863346633323764346339373834363433373730383861
|
||||
64613139366566653035656531363933313234343265653535636464323839336165653637323432
|
||||
61386236383830663230613335303437633737346232316135353262396433376439643562353438
|
||||
62393431396262383965303436663431326239626666353735636465656530333236326137313062
|
||||
38323866346433646261633633373031346334396561323536376563363035633565643137346137
|
||||
33393930326166303439623463623631333339383566383565363536333036626630303130633432
|
||||
32646364336665363966626665323465346363346137636536303362663935643831326536633739
|
||||
34353361656635623965383332643936336663373330653563353837353230326531366238353035
|
||||
32356465653966643831633963623239666136393436663932353366633231343534626234336539
|
||||
32663133616162366238323635616531373335383535653732373432613938396535343339383037
|
||||
37376461646438383434633364373339303137333134333138323630633731366533633061373634
|
||||
38353034356332373134373833393431346539306265313965623663343433343361613634646563
|
||||
35383234623362633935383362393763363938643864373266336339373265353933336232303965
|
||||
61666133356430663764323437373632643533333066616232336236633164363965356339326161
|
||||
63626437663736666536373965316230303239653764356338613638623233643835383637386661
|
||||
38616330623739306338396639323739383661363431396531613963393732396433346363616438
|
||||
33303030663231313263616163346563336631643563316465373866383162356562653165333766
|
||||
33333966303932396336393263363039383930353334313061316335313238363564313639646637
|
||||
34316562386366306238376465326631336539643936663264306631303335346131343939663965
|
||||
62316566393236643938633731356465373435646238646661333935323563333231363361663638
|
||||
31313832613032636466316263386561363665333432653931393835346535653837303937363764
|
||||
65353561326162313831303865393665353732346536653262316131643863373039636336616132
|
||||
38666362363137663266306634346438636430353036616536613332376535633662326432383431
|
||||
66353539376132373165633634376230393738393831313831663535613430633937383732356163
|
||||
32356639626237303861336364376663306465393130373136366461666233626333346437316563
|
||||
65616132326637313134656665323439366362613634376536373631656234343934396532333539
|
||||
62306163313062393365613338326464633136376562383130303638616364366139373734346236
|
||||
36333665306666633465396437633161356664643235326665633537666366316662643339626430
|
||||
66393335343463663662363561626534386435373636626131393263626664336164633062393239
|
||||
39613737383834363661343662323436326236326464343732326232316264303135613035323039
|
||||
62313539363532333738343664663830373163346436636533663164333438623338623332303136
|
||||
37633065336162326361333430363464656662626237366530343765643937333866373831666336
|
||||
36333363633830343836383235613562633435663166386264343936666264323561343938393232
|
||||
38323235636266616266333535376661663063363562376461336437376661633734633165326661
|
||||
326437613235333261643465663663343838
|
||||
|
|
|
@ -0,0 +1,139 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
# Copyright: (c) 2019, Alexandre Iooss <erdnaxe@crans.org>
|
||||
# GNU General Public License v3.0+
|
||||
|
||||
"""
|
||||
This module simulate the edition of a MoinMoin wiki page
|
||||
|
||||
Example:
|
||||
moinmoin_page:
|
||||
url: https://wiki.crans.org/WikiErdnaxe
|
||||
user: WikiErdnaxe
|
||||
password: HoTuNeMeConnaisPas
|
||||
content: "{{ lookup('template', 'mapage.j2') }}"
|
||||
revision_comment: Bip bip
|
||||
"""
|
||||
|
||||
import re
|
||||
import urllib.error
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
def login(url, user, password):
|
||||
"""
|
||||
Log in and return session cookie or None if failed
|
||||
|
||||
:param url: random wiki url (not root page)
|
||||
:param user: wiki user
|
||||
:param password: user's password
|
||||
:return: session cookie
|
||||
"""
|
||||
# Send a HTTP POST request
|
||||
data = urllib.parse.urlencode({
|
||||
'action': 'login',
|
||||
'login': 'Connexion',
|
||||
'name': user,
|
||||
'password': password
|
||||
}).encode()
|
||||
req = urllib.request.Request(url, data)
|
||||
try:
|
||||
response = urllib.request.urlopen(req)
|
||||
cookie = response.getheader('set-cookie')
|
||||
except urllib.error.HTTPError as e:
|
||||
# If 404, then also return header
|
||||
cookie = e.getheader('set-cookie')
|
||||
|
||||
# Check that authentication worked
|
||||
assert cookie, 'server did not return a session cookie'
|
||||
return cookie
|
||||
|
||||
|
||||
def edit_ticket(url, cookie):
|
||||
"""
|
||||
Return edition ticket of url
|
||||
|
||||
:param url: page to edit
|
||||
:param cookie: session cookie
|
||||
:return: edit ticket
|
||||
"""
|
||||
# Send request with session cookie
|
||||
suffix = "?action=edit&editor=text"
|
||||
req = urllib.request.Request(url + suffix)
|
||||
req.add_header("Cookie", cookie)
|
||||
content = urllib.request.urlopen(req).read().decode('utf-8')
|
||||
|
||||
# Search for ticket
|
||||
search = re.search('name=\"ticket\" value=\"([^\"]*)\"', content)
|
||||
assert search, 'no edit ticket was found'
|
||||
return search[1]
|
||||
|
||||
|
||||
def edit(url, user, password, content, revision_comment):
|
||||
"""
|
||||
Edit a MoinMoin wiki page
|
||||
|
||||
:param url: page to edit
|
||||
:param user: wiki user
|
||||
:param password: user's password
|
||||
:param content: content to place on this page
|
||||
:param revision_comment: revision comment
|
||||
"""
|
||||
# Connect and get edit ticket
|
||||
cookie = login(url, user, password)
|
||||
ticket = edit_ticket(url, cookie)
|
||||
|
||||
# Create request and send
|
||||
data = {
|
||||
'button_save': 'Enregistrer les modifications',
|
||||
'category': '',
|
||||
'comment': revision_comment.encode("utf-8"),
|
||||
'savetext': content.encode("utf-8"),
|
||||
'action': 'edit',
|
||||
'ticket': ticket
|
||||
}
|
||||
req = urllib.request.Request(url, urllib.parse.urlencode(data).encode())
|
||||
req.add_header("Cookie", cookie)
|
||||
urllib.request.urlopen(req)
|
||||
|
||||
|
||||
def run_module():
|
||||
# Define arguments that should be passed
|
||||
module_args = {
|
||||
'url': {'type': 'str', 'required': True},
|
||||
'user': {'type': 'str', 'required': True},
|
||||
'password': {'type': 'str', 'required': True},
|
||||
'content': {'type': 'str', 'required': True},
|
||||
'revision_comment': {'type': 'str', 'required': True},
|
||||
}
|
||||
|
||||
# Define arguments that are returned
|
||||
result = {
|
||||
'changed': False,
|
||||
}
|
||||
|
||||
# Our AnsibleModule
|
||||
module = AnsibleModule(
|
||||
argument_spec=module_args,
|
||||
supports_check_mode=True
|
||||
)
|
||||
|
||||
# TODO: get current wiki page and compare
|
||||
result['changed'] = True
|
||||
|
||||
# If not is check mode and page need to change, then update page
|
||||
if not module.check_mode and result['changed']:
|
||||
edit(**module.params)
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
def main():
|
||||
run_module()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,18 @@
|
|||
---
|
||||
- name: "Create wiki page documenting {{ ansible_hostname }} (physical)"
|
||||
when: ansible_system_vendor != 'QEMU'
|
||||
moinmoin_page:
|
||||
url: "{{ moinmoin_base_url }}/Serveur{{ ansible_hostname|title }}"
|
||||
user: "{{ moinmoin_user }}"
|
||||
password: "{{ moinmoin_password }}"
|
||||
content: "{{ lookup('template', 'server.j2') }}"
|
||||
revision_comment: "Ansible running for {{ ansible_hostname }}"
|
||||
|
||||
- name: "Create wiki page documenting {{ ansible_hostname }} (virtual)"
|
||||
when: ansible_system_vendor == 'QEMU'
|
||||
moinmoin_page:
|
||||
url: "{{ moinmoin_base_url }}/Virtuels/Serveur{{ ansible_hostname|title }}"
|
||||
user: "{{ moinmoin_user }}"
|
||||
password: "{{ moinmoin_password }}"
|
||||
content: "{{ lookup('template', 'server.j2') }}"
|
||||
revision_comment: "Ansible running for {{ ansible_hostname }}"
|
|
@ -0,0 +1,62 @@
|
|||
= Serveur {{ ansible_hostname|capitalize }} =
|
||||
|
||||
{% if wiki_doc_intro is defined %}
|
||||
{{ wiki_doc_intro }}
|
||||
{% endif %}
|
||||
== Caractéristiques matérielles ==
|
||||
|
||||
{% if ansible_form_factor != 'Other' and ansible_form_factor != 'Unknown' %}
|
||||
'''Forme du serveur''' :
|
||||
{{ ansible_form_factor }}
|
||||
|
||||
{% endif %}
|
||||
'''Matériel''' :
|
||||
{{ ansible_system_vendor }} {{ ansible_product_name }}
|
||||
|
||||
'''Domaine''' :
|
||||
{{ ansible_domain }}
|
||||
|
||||
'''CPU''' :
|
||||
{{ ansible_processor_count }} processeur(s)
|
||||
avec {{ ansible_processor_cores }} cœur(s)
|
||||
divisé(s) en {{ ansible_processor_threads_per_core }} thread(s).
|
||||
|
||||
'''Mémoire''' :
|
||||
{{ (ansible_memory_mb.real.total/1024)|round(1) }} GB de mémoire RAM
|
||||
et {{ (ansible_memory_mb.swap.total/1024)|round(1) }} GB de SWAP.
|
||||
|
||||
=== Stockage ===
|
||||
|
||||
|| Point de montage || Taille || Disque ||
|
||||
{% for m in ansible_mounts %}
|
||||
{% if m.fstype == 'ext4' and 'size_total' in m %}
|
||||
|| {{ m.mount }} || {{ m.size_total|human_readable(unit='G') }} || {{ m.device }} ||
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
=== Interfaces réseau ===
|
||||
|
||||
|| Device || IPv4 || IPv6 || MAC ||
|
||||
{% for i in ansible_interfaces %}
|
||||
{% set interface = vars["ansible_" + i] %}
|
||||
{% if interface.active and interface.type == 'ether' and 'ipv4' in interface %}
|
||||
|| {{ interface.device }} || {{ interface.ipv4.address }} || {# No newline #}
|
||||
{% for ip in interface.ipv6 %}{{ ip.address }} {% endfor %} || {# No newline #}
|
||||
{{ interface.macaddress }} ||
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
== Caractéristiques logicielles ==
|
||||
|
||||
'''Système d'exploitation''' :
|
||||
{{ ansible_lsb.description }}
|
||||
|
||||
'''Noyau''' :
|
||||
{{ ansible_kernel }}
|
||||
|
||||
'''BIOS installé''' :
|
||||
{{ ansible_bios_version }} datant du {{ ansible_bios_date }}
|
||||
|
||||
----
|
||||
CatégorieCrans CatégorieCrans/LesServeurs
|
||||
|
Loading…
Reference in New Issue