Automagic ansible updates using the reports.
This commit is contained in:
parent
877396dc15
commit
7ce165553d
5 changed files with 209 additions and 137 deletions
213
inventory.yml
213
inventory.yml
|
@ -1,106 +1,109 @@
|
|||
$ANSIBLE_VAULT;1.1;AES256
|
||||
65343732383530343864623831386139383135366432373638333330643164633465336363616566
|
||||
3834663038326663353535613133626666656333613130390a383830356534373337653433333236
|
||||
65633337373634393664356135366234303835363562653862383032653236666462333430613663
|
||||
3238313863383862620a643630666130663639363836313632643066656662313937626636333637
|
||||
39653630363433626535663665633562333534656530396331326532653434356630323462633937
|
||||
64643339656131303065356232623038663734323832613965313266663132386130613965353364
|
||||
36303030646634366165623632666533626162663430663761336538326232616131653432383633
|
||||
34343166343936613434373037616331383632346130386165353031616132616361356663633333
|
||||
63383866646537373463306533333965373065633130353630623263396436636335633531303136
|
||||
35636431396332666634613133393961353766653832613135343036393430303435336532353762
|
||||
36613062343663313037383539373362376238376263353233356138643461623431373231633432
|
||||
65626362653533333163653038326432306361383335396530646534303930333366643838316538
|
||||
64306635353937623766323034333235396539623334326232663763636330633537383737343461
|
||||
36613238393637633830666465373066636639313833666432643766316438633861333563653633
|
||||
35396532623936653132363635373862343138353766373034343135303139353166623237643266
|
||||
32633963373061393833326238316334636562636234663532656564313134636131343339646334
|
||||
62623038633861363135306134326466383237376663636566386163336363383661313961323761
|
||||
38626432326664373330306362373863356536376561323534343636353030376639656464616361
|
||||
34373539353637353837633833323935626663653466666264363132343836303537376665353262
|
||||
30656138616531616532343031323261376235636161333631306263623263613737353837373838
|
||||
34653537656231383435396365323064643961653932386533383664343033333436616236343065
|
||||
32663837663833623939373161373866643332303339643536393663396433626631313262356437
|
||||
35343663616137613838393633623034393262383736636634303363333463353737363535336332
|
||||
34303766643831666538343030386230393531386237313130663464393862653363666563333164
|
||||
38663039356239616339613565323763653339616665613634356164316234326134343632663032
|
||||
38303539376163373166353865653038646233613736376237326361316132323834643037326430
|
||||
35306231613166616562336262666233313731336262336361633135333563356566633438363663
|
||||
36333236646531343663363961666561643065366637393831323464386232356563353134643638
|
||||
31393531623266633534666131323233653661396261376639356665613630346330303663303239
|
||||
31326163303332653631636462343834393766626538616135373062613066323932366265616164
|
||||
37376130306462613130363331636466393233636261313735386562323035343066353030313664
|
||||
65646134386534323061323733643537616565333939356433336633316537383535636661316231
|
||||
31313362313338313839383632613364396138643934646636623939633130316433616565376132
|
||||
66306562383966396131323132623064663365313663636666663337363735663032623031656638
|
||||
65346636346137663962373863653434343134393531336538616134373136373361363330316130
|
||||
32333732373035363533313462376335613364616462353664633562393064346561323737303361
|
||||
38613431346535383930376362393763363438386338613736306264333638356661343533636362
|
||||
65356238623533636632303461616132343833323861636632636133643666653135373330383263
|
||||
34306264653038353664306539623836613266356631663764353538383163633136653338616261
|
||||
32393638616231633937363132373861343231326232383130623162636464633636653532333862
|
||||
30383162653862326661303064363165343464323835326530353836323464396366396238363831
|
||||
61623836656134613036383265306465666263663066646238373739306338366233333235336464
|
||||
32376439643838666138333864393937316534653735306430313930353165303261333432646664
|
||||
63633432613539343433313438666539616131393634646665356531366535333731613338663964
|
||||
33636538353530336661343564356131623937306164306137626139346462336532663064323838
|
||||
37396561376365343638343532323534303835333966333530373937396136303032376663663831
|
||||
38646238653838653766336337316135323730356364303333626637333562393562363433363431
|
||||
32336235316163303463396461333035613433366138666561663734313539346433366239666132
|
||||
34326630666437323762353839653635666466613930643330636666663661393630623262343735
|
||||
35356362343339613166656431346531326334383164633737383531616166666238666231633238
|
||||
39323730393262626566363136666339323235306430306466333232373664303236376265626334
|
||||
61306466363138303463383666326330613331613463616662383138656536663266313866656330
|
||||
30663234393730363333383830323234306430653734376233636230356562643530636364343639
|
||||
30656233653635396230636439366137626634396536363038306561656231666262363737356565
|
||||
65646463613830623732623537326136303131346564336433646166366564356363393438373162
|
||||
30613837646332373363323166363234663632366139633637363530393966333534383735383139
|
||||
31363435396531666233313061626139326137323738333765336237373234346238636232363630
|
||||
31366431623035353965326231636431303730393037363466346237663032356261386562313039
|
||||
30353761313135303438373233656534343962363535383565383934393130356633353135666439
|
||||
62313039333263633634386464366661623666363730356265633831616462386566623934613235
|
||||
34363063636136316362613235306633636630616663326563663539333332656162636631376266
|
||||
31613364303061306539626365303962663938316461396462303863653131346337326364626334
|
||||
39326662666430346632323136653335383861333730633064323963616564663535653935386135
|
||||
33626130333433346362656235613364643434366339666162323761383864303964366330303861
|
||||
61663935623766653930376163366130336562666231316433326137333463383831613934323937
|
||||
63626239643730373835363761613065303765656336626565386664323563656636333638656566
|
||||
32313231643763646532303336653465616261613965663136653430326365336530656464396630
|
||||
63313164613238613334326535613031633861623135366130373461313066646536346565376365
|
||||
32626564353930383763303462663734623030353865333034623034323466646433333163633139
|
||||
30663836393461346664363163346138373166306239396132653735633461313036663337336337
|
||||
38323238633561303237393161323638303962616131636138353963636163396563363066353562
|
||||
38356637353231623031313261663537383931323464393030323235353762646164646539626666
|
||||
64633438323766303038663865326565336439616638613632646530316137336263653461333835
|
||||
35383938633861343635386364373665393661393563376264346433663030613465323439386335
|
||||
34616566636230373330643564323937656637313232616139313737643332666662643262616266
|
||||
34303531616663353066366261653337363533613364396239393836363132343636643638663863
|
||||
61653863363535646336626536623963653862313066383366376161633339303537653765353666
|
||||
64633964343864363862323936613565643531396336313839336438393333313162373836383836
|
||||
34313238626132373436386237646532373831633630663563643835316638386666336438366235
|
||||
61666335643734643938363465663465666563356237626139333836653032336336633762353639
|
||||
30323334373136323033346661373861376435396662383861333030663866663336346562303936
|
||||
35366665356236623862306163396536326564373661613436323435313566643132356631356334
|
||||
33626261306634623164656534663132383932313666326665323836343462636435326561666139
|
||||
33616131386634666138396431653161376462376237636262373638666665353432343438386462
|
||||
66643162373866313838303862393561323063303236616333376235633533663733343730663136
|
||||
65646336663736323031363234373032366535633230383935303561613031303664653966393632
|
||||
65643265366237653430656463393337626439373339643565623630336162303232396364656539
|
||||
39336631333862326638353365376661393233386236653930386530643133376635323038363734
|
||||
62383863653837666331633438396337313262343235313265356262323430326162343065396163
|
||||
32636363313965653736306261306337643166383330613434666433623637313136356139623132
|
||||
38353761613036363062313038333030646237666336646462326233323137663635633232396333
|
||||
31396533653332396230386339663639386337613639656539346130626663323665393730363239
|
||||
33333263616339333535616237633763316262623763393562653764393235326566616165376164
|
||||
35366632393731643235376366643466613132373333326462663336336432656661383763663438
|
||||
36663239343161656363633363313862643736363636326236366232646335313766336161613536
|
||||
34323533313563393835313066393237303366396165333261383133633332343835653862303331
|
||||
33346432356262396138356239663633333864333936623861663931303934646361336337306462
|
||||
65313337326531393533333638353663336139343365376437343035636462303138393339346264
|
||||
34396138346232666166336436333634633361353565393661343838373834663438393138373732
|
||||
63346639346535313835613430373839373366383266393039613631643830353933373834383538
|
||||
31613339646261346439306139633337353366313832303261663063633837383438366565373733
|
||||
64656366386637393836326663363532626361373231623630316439323431643434373233313063
|
||||
33663966643539623731356238613033316231633338393965636136313463383937353830643463
|
||||
39663135623664316666363531316339376135663139323865373538623165613033313132326130
|
||||
33336565396632303131653635333133663162313538333035376336353737646633
|
||||
30643431666466366336636534366239663662626665383762356437633130393565373162393137
|
||||
3537333262303563623965363839356263316533633036630a323138643764653031376663323439
|
||||
66666637636562633233626539666565666238623039333565323439336235353635303633306163
|
||||
3636663339343963660a323662313032306363623237626464303166646231646461306637306332
|
||||
36613936313631336131616465316136316336623063633432626637636433333365356234356235
|
||||
66643233313837343163366365623939373031336363633066373831323833336463393565306637
|
||||
62323364653233366539393065643338623231303062333761333464376462306536653839303762
|
||||
37636435353532313431636430626466353031616263653531343963306139363237303737643436
|
||||
66656336343134646336393163393831313435616263366337623130633661323838393861323238
|
||||
33356661396562346461386663376536363235626639333430616163613262376361346561336563
|
||||
62356137633931643830643532363563323534626339353334636635643739363439353437356535
|
||||
32343662393936356130316134626330336531653864313138366638643561306433316135353463
|
||||
36613364316563353865346165366566643132346261613638373366396237356361386335376134
|
||||
63366134383561653462303731363135663333303963356662643935356564373366326130313734
|
||||
37646536386135343731373534363366386637346233643337653733623835626630316336646436
|
||||
62306335643562623464613637343736643866376633353761346166613831313936616665313562
|
||||
31316438343731303064303830393366303339343736623365653864383432636330373032326136
|
||||
33643837396232656136643262643438393531353639643665613965376331316262626634623065
|
||||
62383066363832313030376532373064346237666639306436373862613736373162313939343163
|
||||
62363930316235353538303632613964373566626464633738646138666537386166643064353562
|
||||
38653161356262336634373734663238643738643962333039396263646334653932636638633139
|
||||
31616138353633386563356233316231373037336166643737376337316666396337393735326434
|
||||
31633437376530333634323666336330623234646461316362663834663763363038363639636131
|
||||
61616431636566346231343634363337306566636234616638353637393137363139633735393033
|
||||
33393464643765616239326232323933613237646234393765653230313330623638323861653265
|
||||
35633132323539333863323662386566383162623464386630326632333638366163663964613636
|
||||
34343361666532363331353438333232326332323435653439396362613361313964303038383966
|
||||
61373036303264326434646561376639386134326236323966333135353939326165303737616436
|
||||
64333738363633373563316165303763393737303265636337653632663362323237383566376131
|
||||
61393436396530356331363035343635646434336435656663653839346266363038346261366330
|
||||
36366534346532656233656630653131396534356133663534656233653864333037653530353062
|
||||
36366534373135623336393637326564663634643633666236643030396537346161666437626433
|
||||
38623133646165333663313034643063316635356436373166323439306462346330643762333730
|
||||
38656633646565316336363231643138666231386234313534373339383863376530623463376462
|
||||
34666563363065663230326532343136633131356132396138336362333032386266393435363963
|
||||
39336265633533636239643139373332623539633666393333623233393462633035363937643130
|
||||
36666433366330643535303066366564376535313561323630646630633232316662363737623830
|
||||
66633336623563346536356538623761356262653465363831346131323933656137376634316239
|
||||
65663662633366623365303934653364363030666439303461633331653164353565626438353963
|
||||
33353933363362306464383766366635393737373334393965383661666535356630386235643363
|
||||
36663238626236303530386332656633326333356231386562316532366634343961633934383731
|
||||
62653837343830373262323262313861303334393035356131333939366166303333616332396237
|
||||
35353037666437653165306230646263633636656266666339643034303631633836396363313964
|
||||
63643832386332313766623661353461386138353536623261363761383334633762303966373063
|
||||
38656538373934333031333434373765316139383466306133353238616138346531343538666236
|
||||
32636438653133393639333961326264306665366462323034613366363832376666653466383730
|
||||
36323561646639333666333435313934613934633863313062306561613361613231376231366630
|
||||
64383561343037636433353538623434383637306461343361353133363130313135386434396662
|
||||
31656633663839643439633563636265346239393032643166623030616431386437343639326165
|
||||
61323463313466636630323264396239376236313639376231336666306464303262623764356235
|
||||
35646638313330623031656131343338663537383262646436383665363535383861616361643638
|
||||
37633263346338353834306365393964363538633566373236366338616661653733653031383335
|
||||
65626234343066356333303438613762656239643433333338323761633230646364313364313964
|
||||
35656439396163393231306239666132326166323763613839656338636231616134396431323231
|
||||
34373333366362316336316366343465346565646564643263333865376239383532306531333666
|
||||
65323631623739343431663931386461643137353237303863353934653939663164323730643564
|
||||
33633535316432653836313334393064303766616562333262656464646133366532383364373065
|
||||
32333436366335386561633664636566613134396164626431323162623566636136353464316363
|
||||
37346433613630666464383830356665323138303931363432393661313263613432636339613236
|
||||
34333262336232363066623565613838386161346662316131303265393166636265326161626666
|
||||
30343639396132653536383163323862333365623664333735316138343763366337656132326165
|
||||
30636330633561623534656234313665393933626637393732346362626335626531386436326363
|
||||
31306539303564633364653061326463653864623061633034623430326636333863343963616632
|
||||
38366366323161343034356337663163623938316432633764383634663835393030623637316662
|
||||
37666566303464373963666234636561623130633739356666643838323663353230623361623734
|
||||
35373133353937356363386134336539616537616338373631313738623138303666366363323032
|
||||
61623636323137376437343334663437613937633738396462383264363037653133653766376565
|
||||
65303964383033323034393034656262376663386261656461323662376162343366396662316661
|
||||
37356136653632373362316432353664343333336532643531633134653039343430616436343835
|
||||
64633234626666643466366439663664313463353162626536343739663161356436613533383630
|
||||
61313264613832333032613630376266346334373136626339633630666630306165343234373639
|
||||
31356330323230623665653762613866396361326330376630666565313734616633353065343430
|
||||
38343137393230373633353962633365633535663264323131336635323637323235613366376135
|
||||
62343431653466636536363131393038613664656138373063393630623564313735343430633365
|
||||
61313137333439333330333466613862663030633565383531356261373763333235303164626565
|
||||
30376365313139633066646534316132393466343533623361323065613662386666343965616361
|
||||
33306637383161653333303031353335303337663231643031323335323336346533303566346433
|
||||
61383637663462303163333233623864316137373363383732646262636136396462633933303738
|
||||
33363336623265353136633966363833313332373136346166373837613531616539633238356639
|
||||
35623035376264306661356135633162383136303836643937393838346233356430623838353066
|
||||
64333433613262633335613630666563666666663030343633633164386461313563626162343033
|
||||
62313934356465616132393465333063373733393463376430333736613638313438333765376436
|
||||
37653435316637313537393831313835306335613838366631333335396230333135326530383038
|
||||
62623535386363633333373361313332643036633932316430643935396662373033653831393462
|
||||
65633337633037663534616337333230353336323065356633363539353035333037353032303133
|
||||
65316232636336376665366564356562386133386130303338376632663234376265653837643932
|
||||
32666130323831373537336565383461393833646336313636646532356635646334313033323736
|
||||
31643933386562656364363638656334343035333638386166333362333330626464373561333636
|
||||
65336362343034363037633831383935306364376331366462643064623262633139313335333862
|
||||
31643730376437383130666534326337656136656161373534313464633135333761643834383832
|
||||
61376132646431386532396239363562613038646162373763333535393930326632306266393933
|
||||
62393336613436343535373834333232343935616630363138613735666532326538616639393939
|
||||
64626164633139643530666438633731386431626163363032313237653530336137383230633934
|
||||
39316564663463626462653830663765353464393065303533333966623364373337353031306238
|
||||
30663764666162346362356465323831363533343664303834343635393963333861653232613531
|
||||
36333363373538313266336661663239633563323366393635383338353761363039323836373231
|
||||
39623039303765333830343436353136313164636466373136393835393363313762303631356262
|
||||
39356230616637363333383566316632636535393661393631343533663664393033343766656665
|
||||
66386434613633616466356536636339636439646463343038303337343662383762303564356430
|
||||
64663466376237376231663366333331653261356335326239303364323638633635666633353364
|
||||
35613332356238303266323737393465313363623132653463646331613436363636326439656366
|
||||
64636538313335656237636235643137373938323539623836306465666462326635353965353465
|
||||
34396532393463633565323731666463386465386163643862333666306433343036333430356164
|
||||
37626165333036653138633337653336336334616336393764373664393138326666373830356239
|
||||
63666530376266313564633832363138383136373830316635326437326666653236313532303766
|
||||
37386262356464323731613633316338373232633530323262333933626563393430396136616365
|
||||
37633835313363623236646533613661653065646564306334353135623336346436616465646135
|
||||
63643333613765313935
|
||||
|
|
|
@ -11,41 +11,14 @@ sendto="collector.steinbeis.schule 1234"
|
|||
cmds=(
|
||||
'uname -a'
|
||||
'uptime'
|
||||
'apt list --upgradeable -o Apt::Cmd::Disable-Script-Warning=true'
|
||||
'systemctl --failed'
|
||||
'w'
|
||||
'ls -ld /home/ansible/.ansible/tmp/'
|
||||
'ip addr show'
|
||||
'ls -d --full-time /home/ansible/.ansible/tmp/'
|
||||
'ip route list default'
|
||||
)
|
||||
# 'ip addr show'
|
||||
# 'apt list --upgradeable -o Apt::Cmd::Disable-Script-Warning=true'
|
||||
|
||||
r="$HOSTNAME: ------- $(date) -------
|
||||
r="$HOSTNAME: ------- $(date --rfc-3339=seconds) -------
|
||||
$(for c in "${cmds[@]}" ; do echo "$c"; $c | sed 's/^/ /' ; done | sed "s/^/$HOSTNAME: /")
|
||||
## -------------------------------------------------"
|
||||
echo "$r" | nc -w 1 -u $sendto
|
||||
|
||||
|
||||
## below is the corresponding collector part:
|
||||
|
||||
# #!/usr/bin/bash
|
||||
# #
|
||||
# # collect messages from reporter and drop it into log files
|
||||
# #
|
||||
#
|
||||
# set -eu
|
||||
#
|
||||
# port=1234
|
||||
#
|
||||
# logdir="/var/log/collector"
|
||||
# [[ -d "$logdir" ]] || mkdir "$logdir"
|
||||
#
|
||||
# nc -k -l -u -p "$port" | while read line ; do
|
||||
# sndr="${line%%:*}"
|
||||
# msg="${line#*: }"
|
||||
# if [[ "$sndr" =~ [a-z0-9]+ ]] ; then
|
||||
# if [[ "$msg" =~ ^-------\ .+\ -------$ ]] ; then
|
||||
# echo "$msg" > "$logdir/$sndr"
|
||||
# else
|
||||
# echo "$msg" >> "$logdir/$sndr"
|
||||
# fi
|
||||
# fi
|
||||
# done
|
||||
|
|
24
tools/collector
Executable file
24
tools/collector
Executable file
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/bash
|
||||
#
|
||||
# collect messages from reporter and drop them into log files
|
||||
#
|
||||
set -eu
|
||||
|
||||
port=1234
|
||||
#logdir="/var/log/collector"
|
||||
logdir="/tmp/collector"
|
||||
|
||||
mkdir -vp "$logdir"
|
||||
|
||||
nc -k -l -u -p "$port" | while read line ; do
|
||||
sndr="${line%%:*}"
|
||||
msg="${line#*: }"
|
||||
if [[ "$sndr" =~ [a-z0-9]+ ]] ; then
|
||||
if [[ "$msg" =~ ^-------\ .+\ -------$ ]] ; then
|
||||
echo "$(date --rfc-3339=seconds) → Message from '$sndr' received."
|
||||
echo "$msg" > "$logdir/$sndr"
|
||||
else
|
||||
echo "$msg" >> "$logdir/$sndr"
|
||||
fi
|
||||
fi
|
||||
done
|
72
tools/emitter
Executable file
72
tools/emitter
Executable file
|
@ -0,0 +1,72 @@
|
|||
#!/usr/bin/bash
|
||||
set -eu
|
||||
|
||||
## maximal age of file in minutes:
|
||||
age="15"
|
||||
|
||||
pbook="lmn-client"
|
||||
logdir="/tmp/collector"
|
||||
debug=false
|
||||
|
||||
## date of latest git commit in ansible repository:
|
||||
git_date="$(date --iso-8601=seconds --date="$(git log --date=iso-strict | \
|
||||
head -3 | sed -nE "s/^Date:\s+(.+)$/\1/p")")"
|
||||
#dir="$(mktemp -d)"
|
||||
dir="/tmp/emitter"
|
||||
mkdir -vp "$dir"
|
||||
touch "$dir/${git_date//T*/}"
|
||||
|
||||
hlist=""
|
||||
n=0
|
||||
|
||||
find_outdated(){
|
||||
hlist=""
|
||||
n=0
|
||||
while IFS= read -r -d '' file ; do
|
||||
$debug && echo -n "Processing host '$file' with IP address "
|
||||
d="$(sed -nE "s/\s+drwx.+([0-9]{4}-[0-9]{2}-[0-9]{2} \S+).*/\1/p" "$file" | head -1)"
|
||||
if [[ -z "$d" ]] || [[ $(date --date="$d" +%s) -lt $(date --date="$git_date" +%s) ]] ; then
|
||||
r='([0-9]{1,3}\.){3}[0-9]{1,3}'
|
||||
ipa="$(sed -nE "s|^\s+default via.+ src ($r) metric.+|\1|p" "$file")"
|
||||
if [[ -z "$ipa" ]] ; then
|
||||
# FIXME: Outdated report format, trying fallback:
|
||||
ipa="$(grep -E "\s+2: en" -A3 "$file" | \
|
||||
sed -nE "s|.+inet (10\.190\.[[:digit:]]{1,3}\.[[:digit:]]{1,3})/.+|\1|p")"
|
||||
fi
|
||||
$debug && echo "'$ipa'."
|
||||
if ! grep -q "$ipa" "$dir/${git_date//T*/}" ; then
|
||||
echo "$ipa" >> "$dir/${git_date//T*/}"
|
||||
hlist="$hlist,$ipa"
|
||||
n=$(( n + 1 ))
|
||||
else
|
||||
$debug && echo "Host already processed before."
|
||||
fi
|
||||
fi
|
||||
done < <(find "$logdir" -maxdepth 1 -type f -mmin -$age -print0)
|
||||
hlist="${hlist//^,/}"
|
||||
}
|
||||
|
||||
run_ansible(){
|
||||
local hsts="$1"
|
||||
if [[ -n "$hsts" ]] ; then
|
||||
if ! echo | ANSIBLE_RETRY_FILES_ENABLED=1 \
|
||||
ANSIBLE_RETRY_FILES_SAVE_PATH="$dir" \
|
||||
ansible-playbook --vault-password-file ~/.vaultpwd \
|
||||
-bi inventory.yml "$pbook.yml" -l "$hsts" ; then
|
||||
while IFS= read -r ipa ; do
|
||||
sed -i "/$ipa/d" "$dir/${git_date//T*/}"
|
||||
echo "IP address '$ipa' removed from '$dir/${git_date//T*/}'."
|
||||
done < "$dir/$pbook.retry"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
#################
|
||||
while true ; do
|
||||
date --rfc-3339=seconds
|
||||
find_outdated
|
||||
run_ansible "$hlist"
|
||||
t=$(( 600/(n*n+1) ))
|
||||
echo -n "Sleeping for $t seconds now ... "
|
||||
sleep $t
|
||||
done
|
Loading…
Add table
Reference in a new issue