Skip to content

Instantly share code, notes, and snippets.

View nitanka's full-sized avatar

Sanyasi nitanka

  • Banglore
View GitHub Profile
@nitanka
nitanka / addhosts.yml
Created August 14, 2017 06:44
Ansible: adding hosts to /etc/hosts from inventory file
name: host mapping /etc/hosts of server
hosts: <hostgroup>
become: true
tasks:
- name: adding hostname mapping /etc/hosts
lineinfile:
dest: /etc/hosts
insertbefore: '^127.0.0.1'
line: '{{ item.0 }} {{ item.1 }}'
with_together:
@nitanka
nitanka / clearcache.yml
Created August 14, 2017 06:49
Ansible: To clear cache of servers
- name: Installing HADOOP CLUSTER
hosts: <hostgroup>
become: yes
gather_facts: true
tasks:
- name: Clearing the cache
shell: sync; echo 3 > /proc/sys/vm/drop_caches
@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>'
@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 / 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 / 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 / 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 / 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-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-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