devops1 Flashcards
devops questions
Difference between Ansible Playbook and Role
Role is a set of tasks and additional files to configure host to serve for a certain role. Playbook is a mapping between hosts and roles.
how do you get a list of all the variables available on a remote machine in ansible
Ansible -m setup
how do you check all the inventory variables for a host in ansible
Ansible -m debug- a “var=hostvars[‘hostname’]” localhost
how do you test connectivity with all the hosts in your hostfile in ansible
Ansible - m ping all
How do you make Ansible code reusable
by using roles
How do you create an Ansible Role file structure
ansible-galaxy init azavea.packer
how to syntax check an ansible file
ansible-playbook –syntax-check buildmachine.yml
how do you call an ansible handler
(handler are used to restart services and do other things when another action is performed.) with a notify: - restart memcached - restart apache
list hosts effected by a playbook
ansible-playbook playbook.yml –list-hosts
In terraform how do you include a module
Inside a resource you run: user_data = “${element(data.template_file.userdata01.*.rendered, count.index)}” and then you have a data section to render the template with variables data “template_file” “userdata01” { count = “${var.instanceCount}” template = “${file(“${path.module}/templates/cloud.tpl”)}” vars { cluster = “${var.cluster}” env = “${var.env}” fqdn = “${format(“${var.serverFunction}-${var.cluster}-%02d.${var.env}.inteliquent.net”, count.index+1)}” hostname = “${format(“${var.serverFunction}-${var.cluster}-%02d”, count.index+1)}” saltRoles = “${var.saltRoles}” serverFunction = “${var.serverFunction}” } }

Limit memory on a docker container
docker run -m=4m limit it to 4meg
Limit cpu on a docker containers
docker run -cpus=1.5
Write a Docker file that uses ubuntu and runs ping www.google.com
FROM ubuntu
run “ping www.google.com”
What is the difference between a docker container and a image?
An instance of an image is called a container. You have an image, which is a set of layers as you describe. If you start this image, you have a running container of this image. You can have many running containers of the same image.
You can see all your images with docker images whereas you can see your running containers with docker ps (and you can see all containers with docker ps -a).
So a running instance of an image is a container.
how to do you clean unused docker stuff
docker system prune -a
Configure iptables to allow all traffic
iptables –policy INPUT ACCEPT
iptables –policy OUTPUT ACCEPT
iptables –policy FORWARD ACCEPT
configure iptables to drop all traffic
iptables –policy INPUT DROP
iptables –policy OUTPUT DROP
iptables –policy FORWARD DROP
Configure iptables to block incoming connections from 10.10.10.10
iptables -A INPUT -s 10.10.10.10 -j DROP
Configur iptables to drop traffic from the 10.10.10.0/24 network
iptables -A INPUT -s 10.10.10.0/24 -j DROP
or
iptables -A INPUT -s 10.10.10.0/255.255.255.0 -j DROP
configure iptables to inbound ssh but disable outbound ssh (alothough allow ssh outbound if it’s from a inbound connection)
iptables -A INPUT -p tcp –dport ssh -s 10.10.10.10 -m state –state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp –sport 22 -d 10.10.10.10 -m state –state ESTABLISHED -j ACCEPT
configure iptables to drop ssh connection from 10.10.10.10
iptables -A INPUT -p tcp –dport ssh -s 10.10.10.10 -j DROP
iptables list rules with line numbers
iptables -L -n –line-numbers
Delete an iptables rule with it’s line number
iptables -D INPUT 2
Insert a rule at the top of the chain in iptables
iptables -I INPUT 1 -s 59.45.175.10 -j ACCEPT
Iptables drop multiple ports from a network range
iptables -A INPUT -p tcp -m multiport –dports 22,5901 -s 59.45.175.0/24 -j DROP
configure iptables to only allow ports 22,80 and 443
iptables -A INPUT -p tcp -m multiport ! –dports 22,80,443 -j DROP
Create a iptables custom chain called ssh-rules and add configure it to be in the main input chain.
iptables -N ssh-rules
iptables -A ssh-rules -s 18.130.0.0/16 -j ACCEPT
iptables -A ssh-rules -s 18.11.0.0/16 -j ACCEPT
iptables -A ssh-rules -j DROP
iptables -A INPUT -p tcp -m tcp –dport 22 -j ssh-rules
make iptables persistant in centos/rhel
sudo yum install iptables-services
make iptables persistant in ubuntu
sudo apt install iptables-persistent