# Day 58: Ansible Playbooks

**Task-01: Creating a File on a Different Server**

Here is my host file look like

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687583291562/e349716e-d5a2-4202-989b-df5db1279cb3.png align="center")

To create a file on a different server using Ansible, you can use the `file` module. write `create_file.yml` using vim

```bash
vim create_file.yml
```

Here's an example playbook:

```bash
---
- name: Create a file on a different server
  hosts: webserver
  tasks:
    - name: Create file
      file:
        path: /home/ubuntu/new_file.txt
        state: touch
```

now run this playbook using following command.

```bash
ansible-playbook create_file.yml
```

your output will be like this

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687583657475/c1072299-57bb-40f3-a387-76b0af1ea0fe.png align="center")

Task-02: Creating a New User

To create a new user using Ansible, you can utilize the `user` module. Here's an example playbook:

To create a file on a different server using Ansible, you can use the `file` module. write `create_user.yml` using vim

```bash
vim create_user.yml
```

Here's an example playbook:

```bash
---
- name: Create a new user
  hosts: webserver
  become: true
  tasks:
    - name: Create user
      user:
        name: newuser
        state: present
```

now run this playbook using following command.

```bash
ansible-playbook create_user.yml
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687583948416/c945bbd9-4529-4865-bffc-ef904c26d9ea.png align="center")

Task-03: Installing Docker on a Group of Servers

To install Docker on a group of servers using Ansible, you can utilize the `apt` or `yum` module based on your Linux distribution.

write `install_docker.yml` using vim

```bash
vim install_docker.yml
```

Here's an example playbook for Ubuntu servers:

```bash
---
- name: Install Docker on a group of servers
  hosts: webserver
  become: true
  tasks:
    - name: Update package repositories
      apt:
        update_cache: yes
      tags: docker
    - name: Install Docker packages
      apt:
        name: docker.io
        state: present
      tags: docker
    - name: Start Docker service
      service:
        name: docker
        state: started
        enabled: true
      tags: docker
```

now run this playbook using following command.

```bash
ansible-playbook install_docker.yml
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687584573516/859c9a13-9906-456f-8bf5-00f120f93485.png align="center")

That was all for today. see you another day with another challenge.
