Table of contents
๐ถ Task-01
- Write an Ansible playbook to create a file on a different server.
firstly configure all 3 servers and master server, for that please refer this blog Help
create a yaml file for the playbook eg. create_file.yml
--- - name: Create a file for web server hosts: all become: true tasks: - name: Create a file file: path: /home/ubuntu/ansible.txt state: touch
ansible-playbook create_file.yml -i /etc/ansible/hosts
Verify that the files are created on different servers.
we can check from the master server too by using the below command.
ansible all -a "ls /home/ubuntu" -i /etc/ansible/hosts
Write an ansible playbook to create a new user.
--- - name: Create a new user hosts: all become: true tasks: - name: Add a user Nilesh user: name=Nilesh07
Run ansible-playbook commands:
ansible-playbook create_user.yml -i /etc/ansible/hosts
To check the created user from the master server use the below command:
ansible all -a "cat /etc/passwd" -i /etc/ansible/hosts
Write an Ansible playbook to install docker on a group of servers.
--- - name: Install Docker on multiple servers hosts: all become: yes tasks: - name: Add Docker GPG key apt_key: url: https://download.docker.com/linux/ubuntu/gpg state: present - name: Add Docker APT repository apt_repository: repo: deb https://download.docker.com/linux/ubuntu focal stable state: present - name: Install Docker apt: name: docker.io state: present become: yes - name: Start Docker service systemd: name: docker state: started enabled: yes
To install docker on multiple servers use the below command:
ansible-playbook install_docker.yml -i /etc/ansible/hosts
To verify that Docker has been installed on multiple servers:
ansible all -a "docker --version" -i /etc/ansible/hosts
Watch this video to learn about Ansible Playbooks.
Happy Learning :)
If you find my blog valuable, I invite you to like, share, and join the discussion. Your feedback is immensely cherished as it fuels continuous improvement. Let's embark on this transformative DevOps adventure together! ๐ #devops #90daysofdevop #AWS #Ansible