---
- name: All-in-One Ansible Playbook
hosts: localhost
become: yes
vars:
user_name: john
file_path: /tmp/test.txt
pkg_name: nginx
tasks:
- name: Create a new user
user:
name: "{{ user_name }}"
state: present
shell: /bin/bash
- name: Install a package
package:
name: "{{ pkg_name }}"
state: present
- name: Create a file
file:
path: "{{ file_path }}"
state: touch
- name: Copy a file from local to remote
copy:
src: /path/to/local/file
dest: /path/to/remote/file
- name: Fetch a file from remote to local
fetch:
src: /path/to/remote/file
dest: /path/to/local/file
- name: Show system memory info
shell: "free -m"
register: memory_info
- name: Display memory info
debug:
var: memory_info
- name: Check if a package is installed
shell: "dpkg -l | grep {{ pkg_name }}"
register: pkg_check_result
ignore_errors: yes
- name: Display the package installation status
debug:
msg: "{{ pkg_name }} is installed"
when: pkg_check_result.rc == 0
- name: Delete a user
user:
name: "{{ user_name }}"
state: absent