Skip to content

Instantly share code, notes, and snippets.

View nitanka's full-sized avatar

Sanyasi nitanka

  • Banglore
View GitHub Profile
@nitanka
nitanka / install-postfix.yml
Created August 14, 2017 09:42
Ansible: Installing postfix
---
- name: Installing postfix
hosts: localhost
sudo: yes
tasks:
- name: Set Postfix option hostname
debconf: name=postifx question="postfix/mailname" value="{{ansible_fqdn}}" vtype="string"
- name: Set Postfix option type as internet site
@nitanka
nitanka / security-setup.yml
Created August 14, 2017 09:40
Ansible: Security setup
---
- name: Fixing some security issues in Ubuntu instance
sudo: yes
hosts: x.x.x.x
vars:
ubuntu_common_ssh_port: 3992
ubuntu_common_required_packages:
- ufw
- fail2ban
- unattended-upgrades
@nitanka
nitanka / create-vpc.yml
Created August 14, 2017 09:31
Ansible: Create VPC
---
- hosts: localhost
tasks:
- ec2_vpc:
state: present
cidr_block: 10.3.0.0/16
resource_tags: { "Environment":"Development" }
region: ap-northeast-1
state: present
instance_tenancy: dedicated
@nitanka
nitanka / create-subnet.yml
Created August 14, 2017 09:30
Ansible: Create subnet in an VPC
---
- hosts: 172.30.1.237
name: Create subnet for database servers
tasks:
- name: Creating public subent
ec2_vpc_subnet:
state: present
cidr: 10.3.1.0/24
resource_tags: { "Environment":"Dev", "Name":"public"}
vpc_id: vpc-6c31ac09
@nitanka
nitanka / create-internetgateway.yml
Created August 14, 2017 09:23
Ansible: Creating Internate Gateway
---
- name: To set up internet gateway
hosts: all
tasks:
- name: creating vpc
ec2_vpc:
region: ap-northeast-1
state: present
cidr_block: 20.0.0.0/16
resource_tags: { "Name":"Test" }
@nitanka
nitanka / create-securitygroup.yml
Created August 14, 2017 09:20
Ansible: Creating security group
- name: To set up internet gateway
hosts: localhost
tasks:
- name: example nat group
ec2_group:
name: natsecuritygrp
description: an example EC2 group
#vpc_id: 12345
region: eu-central-1
ec2_access_key: "{{ lookup('env', 'AWS_ACCESS_KEY_ID') }}"
@nitanka
nitanka / sshportchange.yml
Created August 14, 2017 08:03
Ansible: Changing the default ssh port
---
- name: Changing ssh default port
lineinfile:
dest: /etc/ssh/sshd_config
regexp: '^Port\s'
state: present
line: 'Port {{ubuntu_ssh_port}}' #give the port number you want to use
#note we need to restart the ssh service
#existing ssh connection will get disconnected
@nitanka
nitanka / adduser.yml
Created August 14, 2017 08:00
Ansible: Add user to the server
---
- name: Creating new user
user:
name: <username>
group: <groupname>
state: present
shell: /bin/bash #default shell
home: <path_to_home> #example /home/username
#if we donot want home directory to be created,then use createhome: no
password: "{{ lookup('env', 'PASSWD') }}" #set the password for the user
@nitanka
nitanka / create-ec2-instance.yml
Created August 14, 2017 07:56
Ansible: Creating ec2 instance (ubuntu) and adding it to host groups
---
- name: creating an instance in AWS using default VPC and Security Group
hosts: localhost
vars:
instance_info:
- name: "< instance name >"
image: "ami-835b4efa" # Ubuntu 14.04
group_id: '<security-group>'
region: '<region-name' #us-west-2, ap-northeast-1
instance_type: '< instance type >' # t2.micro, mx.xlarge etc
@nitanka
nitanka / create-ebs.yml
Last active January 12, 2023 16:40
Ansible: Adding EBS volume to an EC2 instance
---
- name: Creating a Volume
hosts: localhost
become: yes
tasks:
- name: Creating a Volume
ec2_vol:
aws_access_key: "{{ lookup('env', 'AWS_ACCESS_KEY_ID') }}"
aws_secret_key: "{{ lookup('env', 'AWS_SECRET_ACCESS_KEY') }}"
instance: '<instance-id>'