Tuesday, March 5, 2024

Ansible Commands which Devops Engineers use on daily bases


 

Ansible Commands which Devops Engineers use on daily bases:


1. ansible-playbook: Executes Ansible playbooks.
ex: ansible-playbook -i <inventory_file> <playbook.yml>

2. ansible: Runs ad-hoc commands or tasks.
ex: ansible all -m copy -a "src=/path/to/local/file dest=/path/to/remote/file"
ansible all -m yum -a "name=httpd state=latest"

3. ansible-galaxy: Manages Ansible roles.
ex: ansible-galaxy install <role_name>

4. ansible-vault: Manages encrypted data within Ansible.
ex: ansible-vault encrypt <file>

5. ansible-galaxy init role_name: Initializes a new Ansible role scaffold.
ex: ansible-galaxy init <role_name>

6. ansible-inventory: Shows Ansible's inventory.
ex: ansible-inventory --list -i /path/to/inventory/hosts

7. ansible-config: Manages Ansible configuration.
ex: ansible-config list, ansible-config view

8. ansible-pull: Pulls playbooks from a version control system and executes them locally.
ex: ansible-pull -U <repository_url> <playbook.yml>

9. ansible-playbook --syntax-check: Checks playbook syntax without executing.
ex: ansible-playbook --syntax-check <playbook.yml>

10. ansible-playbook --list-hosts: Lists hosts defined in a playbook.
ex: ansible-playbook --list-hosts playbook.yml

11. ansible-playbook --tags: Runs specific tagged tasks within a playbook.
ex: ansible-playbook --tags=tag1,tag2 playbook.yml

12. ansible-playbook --limit: Limits playbook execution to specific hosts or groups.
ex: ansible-playbook --limit=<host_pattern> <playbook.yml>

13.ansible-vault edit: Edits an encrypted file.
ex: ansible-vault edit secrets.yml

14. ansible-doc: Displays documentation for Ansible modules.
ex: ansible-doc <module_name>

15. ansible-config view: Displays the current Ansible configuration.
ex: ansible-config view

16. ansible-config dump: Dumps the current Ansible configuration variables.
ex: ansible-config dump

17. ansible-config list: Lists configuration settings.
ex: ansible-config list

18. ansible-console: Starts an interactive console for executing Ansible tasks.
ex: ansible-console

19. ansible-lint: Lints Ansible playbooks for best practices and potential errors.
ex: ansible-lint <playbook.yml>

20. ansible-vault encrypt_string: Encrypts a string for use in a playbook.
ex: ansible-vault encrypt_string <string>

21. ansible-vault rekey: Rekeys an encrypted file with a new password.
ex: ansible-vault rekey <file>



hashtagdevops hashtagansible hashtagcommands hashtaglearning

Friday, February 2, 2024

Docker Install and Verify

 

Docker

Docker provides the ability to package and run an application in a loosely isolated environment called a container. The isolation and security allows you to run many containers simultaneously on a given host. Containers are lightweight and contain everything needed to run the application, so you do not need to rely on what is currently installed on the host. You can easily share containers while you work, and be sure that everyone you share with gets the same container that works in the same way

INSTALLATION Docker Desktop is available for Mac, Linux and Windows https://docs.docker.com/desktop 

View example projects that use Docker : https://github.com/docker/awesome-compose 

Check out our docs for information on using Docker : https://docs.docker.com

Two step process:

  1. Set up the Docker repository
  2. Install and update Docker from the repository.

Set up repository

Update the apt package index and install packages to allow apt to use a repository over HTTPS:

$ sudo apt-get update

$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

Likely all of the above is already installed.

Add Docker’s official GPG key:

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Verify that you now have the key with the fingerprint 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88, by searching for the last 8 characters of the fingerprint.

$ sudo apt-key fingerprint 0EBFCD88

pub   rsa4096 2017-02-22 [SCEA]
      9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid           [ unknown] Docker Release (CE deb) <docker@docker.com>
sub   rsa4096 2017-02-22 [S]

Now add the repository:

$ sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

Install Docker Engine

Update the apt package index, and install the latest version of Docker Engine and containerd

 $ sudo apt-get update
 $ sudo apt-get install docker-ce docker-ce-cli containerd.io

Verify Installation:

$ sudo docker run hello-world

Run Docker without sudo

As installed above all Docker commands need to be prefixed with sudo. Let's change this as follows:

  • Create a group, call it docker.
$ sudo groupadd docker
  • Add your user to the docker group.
$ sudo usermod -aG docker $USER
  • Run the following command to activate the changes to groups:
$ newgrp docker 
  • Verify that you can run docker commands without sudo.

$ docker run hello-world


GENERAL COMMANDS

Start the docker daemon 
docker -d 

Get help with Docker. Can also use –help on all subcommands 
docker --help 

Display system-wide information 
docker info

IMAGES 
Docker images are a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings.

Build an Image from a Dockerfile 
docker build -t 
Build an Image from a Dockerfile without the cache 
docker build -t . –no-cache 
List local images docker images Delete an Image 
docker rmi 
Remove all unused images 
docker image prune 

CONTAINERS 
A container is a runtime instance of a docker image. A container will always run the same, regardless of the infrastructure. Containers isolate software from its environment and ensure that it works uniformly despite differences for instance between development and staging.

Create and run a container from an image, with a custom name: 
docker run --name <container_name> <image_name>
Run a container with and publish a container’s port(s) to the host. 
docker run -p <host_port>: <container_port> <image_name>
Run a container in the background 
docker run -d  <image_name>
Start or stop an existing container: 
docker start|stop <container_name>  (or <container_id>) 
Remove a stopped container: 
docker rm <container_name>
Open a shell inside a running container: 
docker exec -it <container_name> sh 
Fetch and follow the logs of a container: 
docker logs -f <container_name>
To inspect a running container: 
docker inspect <container_name> (or <container_id>) 
To list currently running containers: 
docker ps 
List all docker containers (running and stopped): 
docker ps --all 
View resource usage stats 
docker container stats