Commit fda570bb authored by Vũ Hoàng Nam's avatar Vũ Hoàng Nam

Add Ansible task files and fix .gitignore file.

parent 6c443f9d
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
[defaults]
inventory=host.ini
private_key_file=~/.ssh/ansible
---
- name: Deploy Small Flask App with docker
hosts: all
become: yes
tasks:
- name: Copy source code file to remote host
copy:
src: files/small-flask-app
dest: /home/jay/app
# - name: Build image
# docker_image:
# build:
# path: /home/jay/app/small-flask-app
# name: small-flask-app
# tag: v1
# source: build
- name: Pull Docker image
docker_image:
name: garovu/small-flask-app
source: pull
- name: Run Docker container
docker_container:
name: small-flask-app
image: garovu/small-flask-app
ports:
- "5001:5000"
state: started
---
- name: Install Docker and manage containers
hosts: all
become: yes
tasks:
- name: Install required packages
apt:
name:
- apt-transport-https
- ca-certificates
- curl
- gnupg-agent
- software-properties-common
state: present
when: ansible_os_family == 'Debian'
- name: Add Docker GPG key
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
when: ansible_os_family == 'Debian'
- name: Add Docker repository
apt_repository: #use for arm64 chipset
repo: deb [arch=arm64] https://download.docker.com/linux/ubuntu jammy stable
state: present
when: ansible_os_family == 'Debian'
- name: Install Docker
apt:
name:
- docker-ce
- docker-ce-cli
- containerd.io
state: present
when: ansible_os_family == 'Debian'
### Hello this is a normal file.
# syntax=docker/dockerfile:1.4
FROM python:3.10-alpine
WORKDIR /src
COPY requirements.txt /src
RUN pip3 install -r requirements.txt
COPY . .
CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0"]
\ No newline at end of file
#!/usr/bin/env python
import os
from flask import Flask
# from pymongo import MongoClient
app = Flask(__name__)
# client = MongoClient("mongo:27017")
@app.route('/')
def hello_world():
# try:
# client.admin.command('ismaster')
# except:
# return "Server not available"
return "Hello from the MongoDB client!\n"
if __name__ == "__main__":
app.run(debug=True)
[ubuntu]
192.168.67.9
[ubuntu:vars]
ansible_user=jay
---
- hosts: all
become: yes
tasks:
- name: Install neofetch
apt:
name: neofetch
state: present
Role Name
=========
A brief description of the role goes here.
Requirements
------------
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
Role Variables
--------------
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
Dependencies
------------
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
Example Playbook
----------------
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
- hosts: servers
roles:
- { role: username.rolename, x: 42 }
License
-------
BSD
Author Information
------------------
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
---
# defaults file for first-roles
---
# handlers file for first-roles
galaxy_info:
author: your name
description: your role description
company: your company (optional)
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)
min_ansible_version: 2.1
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
---
# tasks file for first-roles
---
- hosts: localhost
remote_user: root
roles:
- first-roles
---
# vars file for first-roles
---
- name: Config Ubuntu Server
hosts: all
become: yes
tasks:
- name: Install firewall
apt:
name: ufw
state: present
- name: Start Firewall Service
service:
name: ufw
state: started
enabled: yes
- name: Allow SSH via Firewall
ufw:
rule: allow
name: OpenSSH
- name: Copy file from local to remote
copy:
src: files/note01.txt
dest: /home/jay
mode: 0644
---
- name: Set up SSH for Ubuntu server
hosts: all
become: yes
tasks:
- name: Generate SSH key
ansible.builtin.openssh_keypair:
path: /home/jay/.ssh/id_rsa
type: rsa
size: 2048
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment