"<p>This tutorial showcases how to use Ansible to automate server setup by creating a new user, configuring the hostname, and then rebooting the server if necessary. We will also cover Ansible Galaxy roles and inventory, explaining how they work in conjunction with the playbook.</p> <p><strong>Ansible Server Setup Automation:</strong></p> <p>The first part of our tutorial we demonstrated how to automate server setup using Ansible. Ansible is an open-source IT automation tool that provides a declarative approach to automate repetitive tasks, such as setting up new servers, configuring software, and deploying applications. The video shows how to use various Ansible modules to create a new user, copy SSH keys, configure the hostname, update and upgrade server packages, and reboot the server if necessary.</p> <p><strong> Ansible Background and Theory:</strong></p> <p>The second part of our tutorial we provided additional background information and theory related to Ansible and the tasks demonstrated in the code. Ansible uses a modular architecture to perform specific actions on target hosts, and modules are standalone scripts that execute specific tasks, such as copying files, managing users and groups, and installing packages. The video also introduces Ansible Galaxy, a repository of pre-built Ansible roles and collections that can simplify the process of creating Ansible playbooks. Finally, the video explains the importance of creating a new user, configuring the hostname, and rebooting the server in the server setup process.</p> <p>Overall, we provided a practical example of how Ansible can be used to automate server setup tasks while also providing an overview of Ansible's key features and benefits. The clear and concise structure of the two parts helps you understand the practical steps involved in using Ansible to automate server setup tasks and provides them with the necessary background information to explore further.</p> <p>Here's a sneak peek of the code we wrote during the role Setup :</p> <pre> <code>- name: " Create user" user: name: "{{ user }}" shell: /bin/bash - ansible.builtin.user: user: "{{ user }}" group: "{{ user }}" - authorized_key: user: "{{ user }}" key: "{{ lookup ('file','~/.ssh/id_rsa.pub') }}" state: present - name: update & upgrade apt: upgrade: dist update_cache: yes - name: change hostname template: src: hostname.j2 dest: "/etc/hostname" register: hostname_changed - name: check domain is set in etc/hosts shell: grep -q "{{ domain }}" /etc/hosts register: hosts_is_registered ignore_errors: true - name: setup hosts lineinfile: dest: /etc/hosts regexp: '^127\.0\.1\.1' line: "127.0.1.1 {{ domain}} {{ domain_name}}" when: hosts_is_registered.rc != 0 - name: reboot reboot: become: true when: hostname_changed.changed or hosts_is_registered.rc != 0</code> </pre>"