From 16be188fffe9978fb0688a2b9cc411c6d1f95c11 Mon Sep 17 00:00:00 2001 From: Vlad R Date: Thu, 23 Jun 2022 13:26:07 +0000 Subject: [PATCH] Cloned the linux folder and repurposed it for the DNACLAB linux machines --- dnaclab_linux/get_logs.yml | 21 +++++++++++ dnaclab_linux/inventory.yml | 8 +++++ dnaclab_linux/reboot.yml | 14 ++++++++ dnaclab_linux/roles/common/vars/main.yml | 10 ++++++ dnaclab_linux/update_apt.yml | 46 ++++++++++++++++++++++++ 5 files changed, 99 insertions(+) create mode 100644 dnaclab_linux/get_logs.yml create mode 100644 dnaclab_linux/inventory.yml create mode 100644 dnaclab_linux/reboot.yml create mode 100644 dnaclab_linux/roles/common/vars/main.yml create mode 100644 dnaclab_linux/update_apt.yml diff --git a/dnaclab_linux/get_logs.yml b/dnaclab_linux/get_logs.yml new file mode 100644 index 0000000..ab242e5 --- /dev/null +++ b/dnaclab_linux/get_logs.yml @@ -0,0 +1,21 @@ +--- +- name: Copy the contents of the "/var/log" folder to the Ansible controller + hosts: all + roles: + - common + become: yes + + tasks: + + - name: Generate the list of files to be copied + shell: "cd /var/log; find . -maxdepth 1 -type f | cut -d'/' -f2" + register: files_to_copy + + - name: Copy the log files + 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/inventory.yml b/dnaclab_linux/inventory.yml new file mode 100644 index 0000000..d8743a4 --- /dev/null +++ b/dnaclab_linux/inventory.yml @@ -0,0 +1,8 @@ +home: + hosts: + ubuntu.dnaclab.net: + telemetry.dnaclab.net: + developer.dnaclab.net: + gitlab.dnaclab.net: + vars: + ansible_ssh_private_key_file = /home/vlad/.ssh/id_rsa diff --git a/dnaclab_linux/reboot.yml b/dnaclab_linux/reboot.yml new file mode 100644 index 0000000..3f0b477 --- /dev/null +++ b/dnaclab_linux/reboot.yml @@ -0,0 +1,14 @@ +--- +- name: Reboot the Ubuntu VMs + hosts: all + gather_facts: no + roles: + - common + become: yes + + tasks: + + - name: Rebooting... + reboot: + msg: "Reboot initiated by Ansible" + test_command: uptime diff --git a/dnaclab_linux/roles/common/vars/main.yml b/dnaclab_linux/roles/common/vars/main.yml new file mode 100644 index 0000000..1a35c55 --- /dev/null +++ b/dnaclab_linux/roles/common/vars/main.yml @@ -0,0 +1,10 @@ +$ANSIBLE_VAULT;1.1;AES256 +34323466633533666237623830316138373237326134336236613536633664373564633163613230 +3938393338663632613061646365613630373635613536360a613039306363616432633030306334 +33353839346339393965616234323561306338626533363238306662383938626364303061633332 +6230623361393438610a383230376431373034306331376536313831633366373665393866373338 +65313334623131323931353436623265623033396266623364313934383865386532623630336164 +32653432613065303363303730353864353739633530376637333662303134613339353062303932 +33646466383561373264333734626364663763393766666664653365386230393562626563376265 +63303939363932636266303566363062643166343064343762313339353839326361383062653036 +6232 diff --git a/dnaclab_linux/update_apt.yml b/dnaclab_linux/update_apt.yml new file mode 100644 index 0000000..5de7512 --- /dev/null +++ b/dnaclab_linux/update_apt.yml @@ -0,0 +1,46 @@ +--- +- name: Update and upgrade packages on Ubuntu VMs + hosts: all + roles: + - common + become: yes + + tasks: + + - name: Update package repositories + apt: update_cache=yes force_apt_get=yes cache_valid_time=3600 + + - name: Get the list of upgradable packages + apt: upgrade=dist + check_mode: yes + register: upgradable_packages + + - name: Print list of upgradable packages + debug: + var: upgradable_packages.stdout_lines + + - name: Upgrade packages on targets + apt: upgrade=dist force_apt_get=yes + + - name: Remove unused packages + apt: + autoremove: yes + + - name: Get uptime information + shell: "/usr/bin/uptime" + register: my_uptime + + - name: Print uptime information + debug: + var: my_uptime.stdout + verbosity: 0 + + - name: Get interface configuration + shell: "ip address" + register: my_interfaces + + - name: Print interface information + debug: + var: my_interfaces.stdout_lines + verbosity: 0 +