From c9d65d3646396afca0a1bca5459b0707ceecf00a Mon Sep 17 00:00:00 2001 From: Konstantin Date: Tue, 3 Mar 2026 16:24:38 +0100 Subject: [PATCH] feat(n8n): Add n8n workflow automation server MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add LXC container configuration (ID 230, 4GB RAM, 2 cores) - Create Ansible role with Docker Compose deployment - Configure PostgreSQL database for production reliability - Add reverse proxy configuration in Caddy HA - Store secrets (encryption key, DB password) in Ansible vault n8n v2.11.0 accessible at https://n8n.renner.uno 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- ansible/inventory/group_vars/all/vault.yml | 258 +++++++++--------- ansible/inventory/group_vars/n8n/vars.yml | 6 + ansible/inventory/pve_hosts.yml | 3 + ansible/plays/install-n8n.yml | 8 + ansible/roles/caddy-ha/templates/Caddyfile.j2 | 8 + ansible/roles/n8n/defaults/main.yml | 36 +++ ansible/roles/n8n/handlers/main.yml | 5 + ansible/roles/n8n/tasks/main.yml | 40 +++ ansible/roles/n8n/templates/.env.j2 | 42 +++ .../roles/n8n/templates/docker-compose.yml.j2 | 39 +++ opentofu/lxc_230_n8n.tf | 35 +++ 11 files changed, 355 insertions(+), 125 deletions(-) create mode 100644 ansible/inventory/group_vars/n8n/vars.yml create mode 100644 ansible/plays/install-n8n.yml create mode 100644 ansible/roles/n8n/defaults/main.yml create mode 100644 ansible/roles/n8n/handlers/main.yml create mode 100644 ansible/roles/n8n/tasks/main.yml create mode 100644 ansible/roles/n8n/templates/.env.j2 create mode 100644 ansible/roles/n8n/templates/docker-compose.yml.j2 create mode 100644 opentofu/lxc_230_n8n.tf diff --git a/ansible/inventory/group_vars/all/vault.yml b/ansible/inventory/group_vars/all/vault.yml index f44549cd..3c66cee6 100644 --- a/ansible/inventory/group_vars/all/vault.yml +++ b/ansible/inventory/group_vars/all/vault.yml @@ -1,126 +1,134 @@ $ANSIBLE_VAULT;1.1;AES256 -39323736313133383663666436626239353162343539363236313032313964393135303362316337 -3066623266386335633133306264393761346436666464340a343831653738633862313566303662 -66346362663166306637343836366334363464363339366663636162633430393766643931383534 -3866363230316563610a613730636138633165626530393666393430656164313833653930623333 -34363439623537346434613238666463363666666165626432346631316235316531633431366332 -30366536393633613166626262623534386563373534656330383032646434386635336538376531 -32643038316363633235663266316261303536646139663736363031633763623435646434303233 -30626134303461333931663633363839363265303337653434323964343736336266643430646236 -30633737306464343866313730393732383330653031363461613338623161343761343966643564 -62623264653064613861363533393532316330373032396131343037663465663833393361343563 -63353864393537656465336666653833653433613139343434383239323164363136626563303234 -33396234383464613136653038353065383135613936346464336262343737343236346631383035 -39333761656336663539623165323535313838613432616437326533346334316535643930306532 -37613565363465666336646632346339353235626566393463343831623465666230626230306237 -35356631666630323436363334313565343032343064326230383665333765343863653864373636 -61663530633366646662353130373364306332356134373561326364323863393066386433336131 -31663363616463636231663961393463343638633430333666343261663735383762643732376239 -63393539663234636465386334666337386465326134613365633663643563623034366135303136 -61653534613139656662303536333834363038643134313031316532383032346263336536613133 -66343032636439306235643662393164313561363232643866313636636335666430643935313437 -62646663653638613333323537363064303334313464303461376662356239626235626335393063 -64333634316634323161333235623638643538336634383134653435613864383663343466616236 -63623235666366303737353430636238363563306135343564323638323836343763376161346561 -62323361656538643737356638643233326436376432303433663139643662363765343035383233 -31393463336430623765386336313134323961316639633633636634313366303065656362636363 -30343566333239656166393739386332653736366637313735643636656239643638366231613063 -37646337636336366164633335313938306239326532363637623937393861643565303931633033 -37353566633935323038323964303438383836623038353331393236666338323062393238616235 -32333339663766326631613533383831396335323763303531343032663639343032393462383830 -65333563356162376366636162656266373362356331376262623865616636333932653839663063 -62383564383164363164386366323731663138313033333664313061623866353065326666376665 -62656433386431626436393561393234376130343661613864653662363133623839363161313364 -62393237316338616162626138666133613866323461366136303663383734613634613161623164 -35663533313936643636616633633836326534623835633835626538633562623737353664316531 -31666330343632643933323333636464393832626666313030396661356432656534376261303966 -32333762646536633261633036393665616534323133663265623266383232633032353930306632 -30353236336633376566623631333665396438336565623634636334303438646561356631636235 -36363064663762363034643434643435656438353132383861306332366264616461343832633836 -63613261376664343633343531646566383737313330616261393039623661316231323931333030 -64663363343232383633636433653537663636306263626337666365353937393961646466623634 -66616136663966313535386238643633303030346164623464633334393334326238343636303235 -39653939656630613064666230666637646534396139616464353538663439393933396264636265 -31393762363562386162613832383966653337303666393330336234643164646238363938326463 -62663839316238383136663739313039393434313537393734346633663566386464376266383230 -37303935666332353166393138303634396361333535386661653465303164303236323966656164 -33383430393930643766383833386464643731336230343165363561393635643735333231323930 -62343138343635636333386263386636386439313166353939376339356539613534363835333134 -33633962313066393832316539383731663261343732313735313637313837306362646262323030 -33376233373537656663666233626363306462363566633062636234356436626536623662313731 -36353866313263353435633864616466646564653536316437666136383039663666613766326264 -64303937326161336464613833643036303763376261346437373564326561393435363135366565 -31383633346639643630363235666633383738646437616162333935636636333766356132376237 -31366438343365363237636563356533343331373939303432636639313764303732396465313861 -38623738633736393161306664623534356465376563313463663639363163366536373061323731 -66326339653637366338646461343532396635323433383832383538643331656364356630313536 -62623037643132393537323566306434343530336463326235626564636133386338653863643632 -34633333613865376335333266313066626334643634323931613064343738313633356234336336 -63383563613438393333643232346266343936633031303737316533363866396134636339303133 -35643839636536303330323832623761386134623062623561303064643961333035396137303630 -31366461646435386263633238646234656338636133396266323165383731613166346435656437 -38326232376466656563376166623139623531613564373564613038636362346639303661336235 -62383032356262393164383632643731316564663430623235633066313566363133336230366533 -39303536333963613665646135393462346231303931396563326235303066303639646534663963 -38393235313239616164626133333865643935323339323737313464336131383138643331326339 -34653833646539303461376461383163636235343431343264303035653835393438656165633438 -35336533343062386163663337646436666338346261333136383534376364353335393032313131 -39633961343461363530363035316437303361666566393162383735623133333164323761343061 -65633662336461323666313935663062336233353962353661356230663339323730343230303839 -66643963613165373933633733303836303338386337336130663331656231636464336163383265 -64303131356563623631613064303038396363653832366163313063333031313066393738623731 -30633635363861613466613664623333326234653831663461633065353463613833386563353864 -30373763353830346333396131313631333830613538633133633838366562363030646137663434 -30346530663864353337343739376133336162623739376664663761623162313165663233393163 -38376131353739636636376366646661613365343134316364316364666134343563323739393865 -32623837613165383431653337383263353865666539323430316434626566346466366530396135 -62646237386438336333363935356538633339363637343934313738333836366130353537666465 -35616530383433386132653634383365303037653133373939323961333830353931343135323235 -39363766336564366333656333373131336132323433313062623363623630646430396338613734 -36636565353135636361343638356663653763356365376364396661653663376431383334356337 -38356430656662386637393037356361656263653264303238643966636535383233626265636661 -35336633366165643434383730626363626563383233663761633834333438633432646465643738 -33313064393738396430366163616634613762626231343037653737653662653037346433396332 -66363861623963373931373466373238613465396137393963313465346433326437343263326434 -34343965663461363738373065613862346563633961643935646663346235353863636232383236 -65656665633739373664653238633965346136616261613066363135633531306335666630303830 -61353863663833383463353762393236353463613061393531336638316130376665356336333930 -35333766373561333965303264343633613637666432363533326636316264323237663366666264 -33386437316232663232646364396262346631383064343061383134326134353134653232386237 -34363133623739613637623564643363313263323666616435663734316638393462316266363937 -34373132613434663061626232386139613664353962643865353537356439313461313239656636 -36303433613435383865333462373533643261373530343732366138383335663632303236313239 -66373230346530306238383439343633323532393632303662373534303337323062643739626438 -37373565653533373164666230616133303764616432613232303065326466323763353061653437 -31366266323236336364366239306532336337306337353631333636396662633165326530386630 -37663666373038643638316336656661656663663464313364623466633435333835373937353961 -35303337343339323166323332396530343331663434306465396634613630626334373530613835 -38343430653439616137393264653836393830383137376131383565613539656232363063346336 -33646538393530643161623539383161623038306362663164643030316366633237333338643630 -34366139626262643462366638323838636263306232323336643334376234326130376163616535 -66356631623737643462383461343137666534633639653264303566643731633234656639633334 -61663463386530666233613231626361643237636237666164353235613562643036626133313430 -37613939633864653062353862613264303565376632643631323135626235393361373433366539 -37646261613539383161626339663063616234376539623964323964356264383865663836306365 -36383435313634303335626337333565623363663163636334363334663962346665343835323835 -39626132333130363463313961343734623839373031626135353361653565346265313963323237 -38633362343639666464356531663061323135623234616463663934356564613535646461656661 -34613235623165656336646161623637396230323734623034373262613832616264386665626134 -35633738396266653837353162323634643563323439303566333138306432373236636638373439 -36356263376634333630663262396164323233666537353961643030376564396335636361616365 -66653035666138343632626633323030633436303563636537666663323466386161343936633638 -39353231303165663335616638666139353635633833653731653830653232316235626238393638 -39336630666561353932363632386538396463666632326134623738316163626366633864373337 -37616233303163326238656262343536623565636665343736363537326132383736613864353033 -33323735396238323663333861653261643834623533666365383866343135623239646135323937 -63373931353461373335353339633964663361303062643561613565313933613432623565396231 -38613832613961343736663964343837306362303130653633663964346364613734316262623163 -65303931663332653532313532646134656262613266646132323665316133623333663165313264 -31346537306139356564613030313037386437376134396462373133656661666436663736633837 -36366339303466346337663736643133346231646361633030663466336634666333383738626235 -36626236316437396438613236306162636539393463303439366563383036373335303730333863 -66333561663137646662373137636439353434643466643134316531636335666263373136653536 -36353436383135633333336462313664613662663736383164346632623038633532633964633664 -35303833386135343034323961653061336333343339393734643162393833366165373032303434 -36393539663739643163636363396134623364393333356435363934316130613230363566323234 -3164 +64613561323132616332313332383530636162663732336662313633366633633863646466363566 +6334363462306533316636313338313062323065353938370a363539366139376232373036306231 +35636133313035623931353264336232663335323162653661333361333161326234306336633030 +6262343662616230330a306663623537643135653930333965613037653065343732633430633337 +35616636393763373736393562656262366564663664336264353164383434316163636230356537 +35383364313966333335643664353438393564386133363463383565623465616663396535363563 +32383663393434396631613934323335656230393532316436326262643731636132383234316238 +38653030626638346365643966626666666138616631646335343561383062376566623638373235 +38353264383238396233386636333532336536373237396636333232643066336361396334646437 +61346361393465663365363766396164613562323034633130653134623165613966623430376232 +65656266386439666266626231626136353635393566303866343233623365316562383463393830 +64336230613963323639343530623236363439633866336433356438383433336137323065633332 +37656237336663663431323832393465383633366137333833373865323037663436383831363663 +39663363643631626535363365353966333936363133613662633965316361306363376138646330 +30373530346136373233616539356435366434303865623532356132653937313664376461393433 +34363536363537376239363466383966373764373161366135303263626239616239313566373831 +30646638313936326165633337663339323338323461383534636439633238326236363938663865 +37653962333037323561643566356566326533613636313031646235623562333139666535616135 +35343134323931386163653331393232613963346261353863663061356630663737353834333532 +32323266323164386165316139656134613537356265353063616434393031323330623430373365 +61366238393666616235343465303731643662356132613732646533646464313439323932366336 +62643637636330653062303761356662343339343266343865336532653237346466623235653763 +61376137643238326562363566623165316565643165616366313138633534663136326337336366 +64636365656361303063663135333839313631336437376262626363386565643465363938306362 +62643833303434373761623738306563313534366166623035636233366537383061656333343562 +37323764356261303563383135613632396462633735626334393139383539306262653637663434 +66396363633761396463386539646336313334613966363466653736643161613430613037633636 +65383035613263323264386639303034633435343966393033356638373465356430653238626638 +37383035646162323834323931303534303935306163653935343130633439616531323334663162 +65313635656333316363646563353864393335306234303237656134333739363431363737356531 +33613534373233313363363463333261616135363131346161393635373533323531623037366664 +33386537323231653764656338626566666634613531663466656163383935356431616565316262 +65396238613630646533656632623339383735363136396366616136666262336461326333356636 +64663839643134353239323236393763303165366535653566653163386239646634346564383463 +38653739383864643537626637306530316238393061663663653862386562623365643133333433 +66343438303033616438343462313430383738386161653966373233613161626566373337336237 +36336535393837656631613864663632396236376663383437653766653735623230383365633639 +38653531623364306433363535316465313165613333393830343466663837393062323662396238 +66373632396461653332616438313039393764333835653530623766313637333632376338363865 +33396435623836643834623739633035323934346134343936303261663534336439363035633334 +37646232353934356630353932333737353361656362656366633164383365336134613333353566 +35663339303366653963613335343531623434653131376362656636623438386330363663326466 +39643531616131386333616231366533343531306364643334646664386438656565636664333835 +39646537376136303832353630663538613633626261333031636134313835316330333563333731 +32663839613237383730306634613833666639386538393361313330316338633465396134353238 +61313534666366626466306133373832656233633638613333343262356236646639666562653163 +31326131663061623831326663643737616566363139393365363464383130346161653932366437 +61386664653832663265373765623861383662663466653337623136306366343236643137663830 +62353539646335363632316663663465653764666533646131633361393731313461663939653338 +30396232353138386566616635343236333636343637383531613662353263353665646234613563 +65666662346361346332623037643732376537353832646637373066653366643162336263383236 +30333861323539623263653730623632653134326239633661666463643839616466643936386336 +31386162333731356361346133326461343361653330643533313736396535646365306635393739 +39303139393339336635646462343134336134333662663431333265643665313566373533346530 +31633430653236353932393863643635356539396138666535356434353666363530386562616636 +32626535663136373537343862363564643035306139623163666533306161326138663534356637 +31383162663837653538366163393762326631616134343133303636383265366430353765366263 +61313535303566383436363833353063633632613633643364306266663662373736373865363136 +64306162653765343463326465313935313261663866623639363830336565383632363763333438 +66393732616330303338386161376638663764353063383463653730303130313731366239333033 +64626561343863363565643932373161366331316131356561666531326637383566643137336637 +61653931323637623433323862373664313139653536383538303638326461616333386539326564 +34643634656662323832383666316436663335343136656364396134343961653738313730613162 +36653134313336363263336238393163653837653933363434353264313038356632626164313233 +35663366656535636663346239663332653161633765333534383662356139383237363830616430 +31363635616235666661303161356436653432396263343261623562616462666264613435313238 +64393039366130336337656362336264303538323735313136666132393563363633623066386237 +63626537323638306265323433333939383735626633383162363262303239373936303038383638 +30363331656137303435363862636365366538336337613437363236326339386230393232646239 +38613763326436396637356361323862393630306632386266353532383861326337343332663163 +35623938316330353731306136663565346265346535633530386131316662396434303034376666 +63366563396234656363363738333663373737663333313937653233376533316638636465376631 +61313964396264316137343335663365393638633230353332323231316132313666383338663033 +35653762303961393933353964356662643864636139663265363963373163643763643964643362 +35616235303830313564636431653031666334313063313862306233316562386235313363353735 +66626334313838316462616232336464336131386335386263666434363966653739316431646366 +61633330366232613237626133393365393733393162333864306239663066613330653739356563 +61343630373665623562383431383165306632336236363065626161346534633663383938643061 +65613565613934656366323065343537623932373435356563303535643038373563336462383438 +66376466666635333261313661333564393865343034646139396535363131613938663836393035 +65303863666666613733393437653561313661363738643562313464376430396530363530643836 +35333964663738363734313438383730316435333834616139636133626230633037363566636663 +62646633393237383631616664366361656234643438353530393738366662643931653665303837 +37353061383765623065313730303036303737376132393262366566353831323931633434663039 +37623466623432366261613561663365373138313432636263363239613364613139373530356531 +39323238386335383235336334376137356635373665613436343134643361653733643633323938 +32326163336335306262353938366335353164653239636233383665663761613835323938336337 +32616432646437326632373633373863343333353331383435316137313133386166626135623366 +66643833343164356434346666666532323339313365353731343364316634303561343230633639 +39663861326561393830333432326438626233313239636234323839306631356466336635656337 +32633263393565333834643736346537376333663363633266306332633130643936356330666231 +31373531353935363364353730313764623535313466376363643630633434643539383133643134 +33616531653063653436636231666234373466383031363866366130336134653066393930303263 +39306462643065333439383266326139316463666430313230626339303739626137333130346430 +34303339366462636565396634653664383363376462373731613135656563363762643563333864 +65363436373936383332396362643635613433333832376563643264326166333831663262336236 +65353631666162373162333533343439636265353038323761393738343861336231383365623061 +62313936373466623632636135616339363735313462343435313230336237303461313336353139 +62623139653063643536363066623338326662613266386531636166323965383038353333396131 +35323330616437343036626462306261346633653038313033613763373931666461373166323365 +35303231373332306238313066353565306632666433343861363063633563336233636339373661 +64613633623431313734653931386261353733383764653865663534316465323034316334333832 +35313461643365626465636138333433346434616138393933353138646366343938666463656633 +64366365346663376430313336623730336563373066613434386266303232646164376538656361 +64613932393666623534336463346164316664343065346330633966356633333661373433643333 +30313931653464353363306263666137613531326461646638343335613237393662373836386366 +34386264316566336464346636373435633638353639323934396534313635353233653163653963 +63313730323866616663663931383534613563393065333634306130393035313137316361373333 +66623137383238346666346663313165356232363930633334613134346466303462653563376335 +38313039323664653939343865623837363231643862393130336230356464666165623763316632 +63303561633535373866386364386162616665363130373563626439316333326438326565326565 +31623364336533383666336137356134343364383934383932363839363637636636356633313531 +66373437373238626461393866333662636136383732636534666133343232656466646636616562 +66656131666139386130343763656664393435633638373839333233373863633631386632663238 +37643430623337633536636461333137353437303930306337303564653635373230643364633361 +66636366646133343535343633663135623964613230353965393265353364653739303032303038 +37623230343864623235663436393562613538653362306561653032626262303733353062386633 +38353462363536373930363639653665633164383333396561383962353335353638333164663336 +32383365376434333639313365616631323232643136353135386639383166633366383763626234 +30323236366630313964653465626262376131653261333133313565613564313162633039643034 +37396561316465323465376230303939393936353064383132393236623865306336383563373531 +63623565346332353266626232306366393331363338623133313731333531623738346263343933 +63366534386363313535396466353431336263353631393133346363626661393163643666306563 +32356233376662653364626338373462363861303434313663646231636237326236663133386234 +61616430653666653933336438313062373636623466626534343361363437396535373839333331 +62393061366138613765303831343066666435643632373931343062323335313938383338393866 +64386636383634303039643161323139363536326536663439663365333530623262653734376662 +66303864666430623135393036643834376565646134306537393134373263663139396361623530 +33333365363964613361333137323939313630336535633562613734383763363464326431613463 +30376235373761323362363263373137633030373833303837303535643330363134663030623733 +37636330323337303439383035386465643235376162366166643563616163373230326263356333 +64333438396563663662333636393162333836653464383739363434303762333161393135323039 +62393963636238616339616563613366366230346434633234323732346637326537 diff --git a/ansible/inventory/group_vars/n8n/vars.yml b/ansible/inventory/group_vars/n8n/vars.yml new file mode 100644 index 00000000..a54982e9 --- /dev/null +++ b/ansible/inventory/group_vars/n8n/vars.yml @@ -0,0 +1,6 @@ +--- +# n8n group variables +# Maps vault secrets to role defaults + +n8n_encryption_key: "{{ vault_n8n_encryption_key }}" +n8n_postgres_password: "{{ vault_n8n_postgres_password }}" diff --git a/ansible/inventory/pve_hosts.yml b/ansible/inventory/pve_hosts.yml index 8656c612..0d34143d 100644 --- a/ansible/inventory/pve_hosts.yml +++ b/ansible/inventory/pve_hosts.yml @@ -26,5 +26,8 @@ netbird.renner.uno ansible_user=root [grist] grist.srv.renner.uno ansible_user=root +[n8n] +n8n.srv.renner.uno ansible_user=root + [synology_nas] nas-1.renner.uno ansible_user=ladmin ansible_python_interpreter=/usr/bin/python3 diff --git a/ansible/plays/install-n8n.yml b/ansible/plays/install-n8n.yml new file mode 100644 index 00000000..8cdb98bc --- /dev/null +++ b/ansible/plays/install-n8n.yml @@ -0,0 +1,8 @@ +--- +- name: Install and Configure n8n + hosts: n8n + become: true + roles: + - role: common + - role: docker-install + - role: n8n diff --git a/ansible/roles/caddy-ha/templates/Caddyfile.j2 b/ansible/roles/caddy-ha/templates/Caddyfile.j2 index 841a690f..34c07f7a 100644 --- a/ansible/roles/caddy-ha/templates/Caddyfile.j2 +++ b/ansible/roles/caddy-ha/templates/Caddyfile.j2 @@ -341,3 +341,11 @@ wiki.renner.uno { } # END ANSIBLE MANAGED BLOCK WIKI +# BEGIN ANSIBLE MANAGED BLOCK N8N +n8n.renner.uno { + import cloudflare + import custom_error + reverse_proxy http://n8n.srv.renner.uno:5678 +} +# END ANSIBLE MANAGED BLOCK N8N + diff --git a/ansible/roles/n8n/defaults/main.yml b/ansible/roles/n8n/defaults/main.yml new file mode 100644 index 00000000..e9cc8038 --- /dev/null +++ b/ansible/roles/n8n/defaults/main.yml @@ -0,0 +1,36 @@ +--- +# n8n configuration +n8n_version: "2.11.0" +n8n_port: 5678 +n8n_data_dir: "/opt/n8n" + +# Public URL (required for webhooks) +n8n_public_url: "https://n8n.renner.uno" +n8n_protocol: "https" + +# Encryption key for credentials (MUST be set in vault!) +n8n_encryption_key: "CHANGE_ME_IN_VAULT" + +# Timezone +n8n_timezone: "Europe/Vienna" + +# PostgreSQL configuration +n8n_db_type: "postgresdb" +n8n_postgres_user: "n8n" +n8n_postgres_password: "CHANGE_ME_IN_VAULT" +n8n_postgres_db: "n8n" +n8n_postgres_version: "16" + +# Execution settings +n8n_executions_data_save_on_error: "all" +n8n_executions_data_save_on_success: "all" +n8n_executions_data_save_manual_executions: true +n8n_executions_data_prune: true +n8n_executions_data_max_age: 336 # 14 days in hours + +# Node environment +n8n_node_env: "production" + +# Default admin (optional, for initial setup) +n8n_default_user_email: "" +n8n_default_user_password: "" diff --git a/ansible/roles/n8n/handlers/main.yml b/ansible/roles/n8n/handlers/main.yml new file mode 100644 index 00000000..432ce4a5 --- /dev/null +++ b/ansible/roles/n8n/handlers/main.yml @@ -0,0 +1,5 @@ +--- +- name: Restart n8n + community.docker.docker_compose_v2: + project_src: "{{ n8n_data_dir }}" + state: restarted diff --git a/ansible/roles/n8n/tasks/main.yml b/ansible/roles/n8n/tasks/main.yml new file mode 100644 index 00000000..4ee87196 --- /dev/null +++ b/ansible/roles/n8n/tasks/main.yml @@ -0,0 +1,40 @@ +--- +- name: Install required system packages + ansible.builtin.apt: + name: + - python3-docker + state: present + update_cache: true + +- name: Create n8n data directory + ansible.builtin.file: + path: "{{ n8n_data_dir }}" + state: directory + mode: '0755' + +- name: Create n8n subdirectories + ansible.builtin.file: + path: "{{ n8n_data_dir }}/{{ item.path }}" + state: directory + mode: '0755' + owner: "{{ item.owner | default('root') }}" + group: "{{ item.group | default('root') }}" + loop: + - { path: 'data', owner: '1000', group: '1000' } # n8n runs as user 'node' (UID 1000) + - { path: 'postgres' } + +- name: Copy n8n configuration files + ansible.builtin.template: + src: "{{ item.src }}" + dest: "{{ n8n_data_dir }}/{{ item.dest }}" + mode: '0644' + loop: + - { src: '.env.j2', dest: '.env' } + - { src: 'docker-compose.yml.j2', dest: 'docker-compose.yml' } + notify: Restart n8n + +- name: Start n8n via Docker Compose + community.docker.docker_compose_v2: + project_src: "{{ n8n_data_dir }}" + state: present + pull: always diff --git a/ansible/roles/n8n/templates/.env.j2 b/ansible/roles/n8n/templates/.env.j2 new file mode 100644 index 00000000..c24c92ec --- /dev/null +++ b/ansible/roles/n8n/templates/.env.j2 @@ -0,0 +1,42 @@ +# n8n Environment Configuration +# Managed by Ansible - Do not edit manually + +# Node environment +NODE_ENV={{ n8n_node_env }} + +# Timezone +GENERIC_TIMEZONE={{ n8n_timezone }} +TZ={{ n8n_timezone }} + +# Public URL and webhooks +N8N_HOST=0.0.0.0 +N8N_PORT=5678 +N8N_PROTOCOL={{ n8n_protocol }} +WEBHOOK_URL={{ n8n_public_url }}/ + +# Encryption key for credentials (critical - do not change after initial setup) +N8N_ENCRYPTION_KEY={{ n8n_encryption_key }} + +# Database configuration (PostgreSQL) +DB_TYPE={{ n8n_db_type }} +DB_POSTGRESDB_HOST=postgres +DB_POSTGRESDB_PORT=5432 +DB_POSTGRESDB_DATABASE={{ n8n_postgres_db }} +DB_POSTGRESDB_USER={{ n8n_postgres_user }} +DB_POSTGRESDB_PASSWORD={{ n8n_postgres_password }} + +# Execution settings +EXECUTIONS_DATA_SAVE_ON_ERROR={{ n8n_executions_data_save_on_error }} +EXECUTIONS_DATA_SAVE_ON_SUCCESS={{ n8n_executions_data_save_on_success }} +EXECUTIONS_DATA_SAVE_MANUAL_EXECUTIONS={{ n8n_executions_data_save_manual_executions | lower }} +EXECUTIONS_DATA_PRUNE={{ n8n_executions_data_prune | lower }} +EXECUTIONS_DATA_MAX_AGE={{ n8n_executions_data_max_age }} + +{% if n8n_default_user_email and n8n_default_user_password %} +# Default admin user (only used on first startup) +N8N_DEFAULT_USER_EMAIL={{ n8n_default_user_email }} +N8N_DEFAULT_USER_PASSWORD={{ n8n_default_user_password }} +{% endif %} + +# Telemetry (disabled) +N8N_DIAGNOSTICS_ENABLED=false diff --git a/ansible/roles/n8n/templates/docker-compose.yml.j2 b/ansible/roles/n8n/templates/docker-compose.yml.j2 new file mode 100644 index 00000000..d14bb7c6 --- /dev/null +++ b/ansible/roles/n8n/templates/docker-compose.yml.j2 @@ -0,0 +1,39 @@ +services: + postgres: + container_name: n8n-postgres + image: postgres:{{ n8n_postgres_version }} + restart: always + environment: + - POSTGRES_USER={{ n8n_postgres_user }} + - POSTGRES_PASSWORD={{ n8n_postgres_password }} + - POSTGRES_DB={{ n8n_postgres_db }} + volumes: + - {{ n8n_data_dir }}/postgres:/var/lib/postgresql/data + - /etc/localtime:/etc/localtime:ro + healthcheck: + test: ["CMD-SHELL", "pg_isready -U {{ n8n_postgres_user }} -d {{ n8n_postgres_db }}"] + interval: 10s + timeout: 5s + retries: 5 + start_period: 10s + + n8n: + container_name: n8n + image: docker.n8n.io/n8nio/n8n:{{ n8n_version }} + restart: always + depends_on: + postgres: + condition: service_healthy + env_file: + - .env + ports: + - "{{ n8n_port }}:5678" + volumes: + - {{ n8n_data_dir }}/data:/home/node/.n8n + - /etc/localtime:/etc/localtime:ro + healthcheck: + test: ["CMD", "wget", "-q", "--spider", "http://localhost:5678/healthz"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 30s diff --git a/opentofu/lxc_230_n8n.tf b/opentofu/lxc_230_n8n.tf new file mode 100644 index 00000000..0523d4d5 --- /dev/null +++ b/opentofu/lxc_230_n8n.tf @@ -0,0 +1,35 @@ +module "n8n" { + source = "./modules/proxmox_lxc" + + target_node = "jupiter" + hostname = "n8n.srv.renner.uno" + vmid = 230 + memory = 4096 + cores = 2 + + onboot = true + cpuunits = 1024 + tags = "n8n;automation;docker" + + hagroup = "olymp" + hastate = "started" + + unprivileged = true + start = true + + storage = "local-zfs" + disk_size = "30G" + + ssh_public_keys = local.common_ssh_keys + + ingress_cnames = ["n8n.renner.uno"] + + description = <<-EOT +n8n - Workflow Automation Platform +https://n8n.io/ + +Deployed via Ansible role: n8n +Port: 5678 +Database: PostgreSQL (local container) +EOT +}