From 18b099f5d80ef2ce9ce15c3cf5b4a4a0e1e9182b Mon Sep 17 00:00:00 2001 From: Vlad Raducanu Date: Tue, 28 Jun 2022 22:47:18 +0100 Subject: [PATCH] Created a global variable files to better access critical values without relying on using the role variable definitons --- dnaclab_linux/get_logs.yml | 8 ++-- dnaclab_linux/global_vars/main.yml | 19 ++++++++ dnaclab_linux/reboot.yml | 10 ++-- dnaclab_linux/roles/common/vars/main.yml | 49 +++++++++----------- dnaclab_linux/{update_apt.yml => update.yml} | 24 +++++----- 5 files changed, 60 insertions(+), 50 deletions(-) create mode 100644 dnaclab_linux/global_vars/main.yml rename dnaclab_linux/{update_apt.yml => update.yml} (62%) diff --git a/dnaclab_linux/get_logs.yml b/dnaclab_linux/get_logs.yml index ab242e5..9709b1d 100644 --- a/dnaclab_linux/get_logs.yml +++ b/dnaclab_linux/get_logs.yml @@ -1,18 +1,16 @@ --- - name: Copy the contents of the "/var/log" folder to the Ansible controller - hosts: all - roles: - - common + hosts: all_servers become: yes tasks: - name: Generate the list of files to be copied - shell: "cd /var/log; find . -maxdepth 1 -type f | cut -d'/' -f2" + ansible.builtin.shell: "cd /var/log; find . -maxdepth 1 -type f | cut -d'/' -f2" register: files_to_copy - name: Copy the log files - fetch: + ansible.builtin.fetch: src: /var/log/{{ item }} dest: /home/vlad/Desktop/ansible/dnaclab_linux/logs/ with_items: "{{ files_to_copy.stdout_lines }}" diff --git a/dnaclab_linux/global_vars/main.yml b/dnaclab_linux/global_vars/main.yml new file mode 100644 index 0000000..e5136c3 --- /dev/null +++ b/dnaclab_linux/global_vars/main.yml @@ -0,0 +1,19 @@ +$ANSIBLE_VAULT;1.1;AES256 +36623338326161363130646439303437616533353066323466353230633331633532323535393036 +3164343061313337366538626566623065613131333539620a613032623335356133383938336564 +39656233363432663565303439636531646333633733316464316162343431336433356534336638 +6237313033366135330a393931376335303930363666646663643036663364643036386364313364 +66306439623838363137383065326231393736376338386536373830356632333034616532613437 +36316666316633346630666330613663336132306366376437326138323962643062393132653638 +37386562396132636131653937343166636463306562373738396264346435353262396662373235 +65393731303932313634666536616239646239363163653532353036656661653362643333663233 +36393964353364643832393438626366303165656432323733303637623766663566343237336235 +36396637366233356335383133306237316435616131376432653530623165353264393565633330 +38393365623734376362643031616231666339323564383034636136386466643233333034643738 +63636130323235656534653831326161643233633538383437303765336530666662333732613036 +33393665373662376438303662663634626430633633313038356533633265663337353533626230 +66623734626664643438386231666438653138383362643138663065626530626361633364616163 +66613266363662366634383066303437393932356264396239393332386163356230396433343137 +30343864626531623236393863303161633137633136663132306563306430626562336534306535 +65383336323839643436343938646435313762333137306364616436393537383939366338313439 +3735336239633863616434643138383534336562633164336633 diff --git a/dnaclab_linux/reboot.yml b/dnaclab_linux/reboot.yml index dc283c1..c80d0b0 100644 --- a/dnaclab_linux/reboot.yml +++ b/dnaclab_linux/reboot.yml @@ -1,15 +1,15 @@ --- - name: Reboots linux host and checks status - hosts: all - roles: - - common + hosts: all_servers become: yes + vars_files: + - global_vars/main.yml tasks: - name: Rebooting... - reboot: - reboot_timeout: 60 + ansible.builtin.reboot: + reboot_timeout: 180 msg: Reboot issued by Ansible test_command: whoami diff --git a/dnaclab_linux/roles/common/vars/main.yml b/dnaclab_linux/roles/common/vars/main.yml index 39740fc..87f5e23 100644 --- a/dnaclab_linux/roles/common/vars/main.yml +++ b/dnaclab_linux/roles/common/vars/main.yml @@ -1,29 +1,22 @@ $ANSIBLE_VAULT;1.1;AES256 -32623135623032666634373536313037663734313837316335613936383235393038373434366236 -3034643538666133396565626235616133646138613931660a383037323333373161616436613639 -61663131636637376531646438643166316439643339333433343665303438336163633638316364 -3534353732666636360a323866656461633461386130663263616132646631383736303864393532 -63346661653135313636646233396166323630633535643735653965313637353538393634336161 -39353736353262373139653763646539323030646432633730333334393562306361626637376163 -63343331646236323232393832373037616333333334643630633262333536323563623032373136 -35663333306264616564343263663930393562356465623232386536656434613664316335303933 -64623238323836336538303361663965316136383533666533306235373663646338313164633534 -32346632386164376630646662336436373036653330643137336233613236633335393939333839 -32313066316631366632386234323862386535343964346261633362386331653130396437643930 -61363265356236343639663931643835646261633038356133613964336466396532633436653939 -35363133343634383638363265636261393761653262353035376339333661386262393966343234 -32326136343233356534316562343132303963323862343038613734356436303865356334643031 -32326335633237353563383166666165373232653134643263386536386638633636336662336166 -37313464323961363237306331373132613962636162303561333836656361653732666563363563 -66376231306539613666363534656263366534303066636166336633656136313531333638386437 -33393462663161336630623532313934373535383130373735633632623032336366616164333233 -63366463623838363638613463633134353830353537636630343636333161616333303862623534 -62633134303939366339616530366634366339643935623265636639323533336530663030383031 -39313061626366656431636533643037323439663463653033343735306632333433663231393332 -32346539643064653662323766653765653235633935643530343031666637636563656339313137 -64316164636136666139393762336530373365616563306231396531373031633337383864643361 -66663539303532656335373139656634363539646533393932326462623163653034383036636333 -62343830343136306565303934383464333233633265386635313066646635663664326135663836 -32356433353832323736363939343165346130363031373731366532313137653435393534393030 -37326635656537366339326538653238353534313934303632343361383164633037353136613562 -37383166653735303330 +37666465316439393863333939643838623635333130646232353430343535623233636261343963 +6463636434646265636535356132343031366536633633630a393830373865656532313466663937 +33326237613537363739653837346165363466313430663262356134666530623135343234373034 +3432306232626166330a643261353639653866633662633431376436626562343134316362326330 +64643233303235303339353062323765643061626437393138613966386465376438616634373334 +32626230346461633364613863356631653838616161333438383662623431353530306236306663 +32376134623266623136316630373136653965336162646662393030386536353938323935393935 +33303336653933393532663065653935643066636435616633613165613163643430326164336134 +64653166633362666463306463336338663061346538326631393732623164326135616162613637 +35313439613635623632326636326665626665633732626533323336366539623038623334323931 +65383032643639623561666134393565343830326537323330373963363461663731366663643565 +32306634343837626566376132643438633361613935323766383464303432366334663961353464 +61313030663335613735656135666464353463313764393034616463383466363765303435363335 +38316330393037616665666264633234613837663933333131306164663732326662663034613164 +31663866333162643630383930353734646561326236656562666262653937623563646639343461 +38396238323862613733313433306133313131353030623931666566613465353165643865316530 +61623534326664653238356537326163633138336165653838653065393033363831373830386635 +64336463333834393430376136373065653463323761643138346465386438343465333365663063 +35353035333863373566623339363333633130343932353432616236656531663266363131663761 +36393531313561333037343861623163393962613930306365363634356236306133643261313939 +3834 diff --git a/dnaclab_linux/update_apt.yml b/dnaclab_linux/update.yml similarity index 62% rename from dnaclab_linux/update_apt.yml rename to dnaclab_linux/update.yml index 5de7512..c3c97dd 100644 --- a/dnaclab_linux/update_apt.yml +++ b/dnaclab_linux/update.yml @@ -1,46 +1,46 @@ --- - name: Update and upgrade packages on Ubuntu VMs - hosts: all - roles: - - common + hosts: all_servers become: yes + vars_files: + - global_vars/main.yml tasks: - name: Update package repositories - apt: update_cache=yes force_apt_get=yes cache_valid_time=3600 + ansible.builtin.apt: update_cache=yes force_apt_get=yes cache_valid_time=3600 - name: Get the list of upgradable packages - apt: upgrade=dist + ansible.builtin.apt: upgrade=dist check_mode: yes register: upgradable_packages - name: Print list of upgradable packages - debug: + ansible.builtin.debug: var: upgradable_packages.stdout_lines - name: Upgrade packages on targets - apt: upgrade=dist force_apt_get=yes + ansible.builtin.apt: upgrade=dist force_apt_get=yes - name: Remove unused packages - apt: + ansible.builtin.apt: autoremove: yes - name: Get uptime information - shell: "/usr/bin/uptime" + ansible.builtin.shell: "/usr/bin/uptime" register: my_uptime - name: Print uptime information - debug: + ansible.builtin.debug: var: my_uptime.stdout verbosity: 0 - name: Get interface configuration - shell: "ip address" + ansible.builtin.shell: "ip address" register: my_interfaces - name: Print interface information - debug: + ansible.builtin.debug: var: my_interfaces.stdout_lines verbosity: 0