• Register
2,500 points
9 2

1. What is Ansible?

Ansible is an open-source automation platform. It can help us with configuration management, application deployment or task automation. It can deploy an application using SSH without any downtime. Ansible is developed or written in Python language.

2. What are the advantages and use of Ansible?

Ansible has a huge number of benefits:
•No Agent: Agent is not required for setting up Ansible. If Box can support ssh and it has python, then no issue to set up Ansible.
•Idempotent: The architecture of Ansible is totally structured around the concept of idempotency. The main or core idea is that only those things need to be added which are needed, and those things will be repeatable without side effects.
•Declarative not procedural: a Normal attitude of other configuration tools of following a procedural process, means do this then do that and so on. But Ansible normally writes the description of the state of machine what we want and it takes proper steps toward fulfilling that description.
•Very easy to learn and low overhead.

3. How Ansible Works?

Ansible mainly categorized into two types of server: controlling machine and Nodes.
Ansible will install on the controlling machine and nodes are managed inside this controlling machine by SSH. Nodes locations are specified by controlling a machine through its inventory.
Ansible deploys modules to nodes using SSH protocol, these modules are mainly stored temporarily on remote nodes and communicate with the Ansible machine through a JSON connection over the standard output. Agent installation in remote nodes is not required for Ansible as it is agentless. So any background process or daemon process not running for Ansible when it’s not managing any nodes. Ansible can able to handle more than 100 nodes in a single system over SSH connection and only one single command ‘ansible’ can be handled the entire operation. But some scenarios we can build ‘playbooks’ where we require to execute multiple commands for deployment. Playbooks are actually holding all the sequential command needs to be executed for performing multiple tasks. Playbooks are in the YAML file format.

4. What’s the use of Ansible?

Ansible mainly used in IT infrastructure to manage or deploy applications to remote nodes. Suppose we want to deploy one application in 100 nodes by just executing one command, then Ansible is actually coming into the picture, but should need some knowledge on Ansible script to understand or execute the same.

    5. Explain what a “playbook” is.

    A playbook is a collection of YAML-based files that forward commands to remote computers with the help of scripts. Developers can configure the whole complex environments by forwarding a script to the demanded systems rather than using different commands to configure computers from the command line remotely. Playbooks are Ansible’s strongest market points and often known as the tool’s building blocks.

    6. State the requirements for the Ansible server.

    The requirements of Ansible server are as follows:

    • Virtual machine with Linux installed on it
    • Python version 2.6 or higher.

    7. What is Ansible Galaxy?

    Ansible Galaxy is a tool adjoint to Ansible to create a base directory structure. Galaxy is basically a website that allows users to find and share Ansible content. You can use the following command to download roles from the website:

    $ ansible-galaxy install username.role_name

    8. How do you use Ansible to create encrypted files?

    To create an encrypted file, you need to use the following command.

    $ ansible-vault create filename.yaml

    After putting this, you will get a prompt to create a password. After creating a password, you’ll have to type it again for confirmation. You will now have access to a new file, where you can add and edit data.

    9. What are “facts” in the context of Ansible?

    Facts are newly recognized and acknowledged system variables of the playbooks. They are used mostly for implementing conditionals executions. They also gather ad-hoc system information.

    10. What are CD and CI, and what is Ansible’s relationship with them?

    CD stands for continuous delivery, and CI stands for continuous integration. Both of them are very known for software development practices. 

    In CD, developers take care of the release of their software products in the condition of releasing it for production at any given time. CI is responsible for each developer uploading regularly scheduled integrations (usually daily), resulting in multiple integrations every day. Ansible is an ideal tool for CI/CD processes, providing a stable infrastructure for provisioning the target environment and then deploying the application to it.

    11. When should i use {{ }}? Also, How to Interpolate Variables or Dynamic Variable Names?

    One of the standard rules is ‘always use {{}} except when:’. Conditionals are always run through Jinja2 as to resolve the expression. So when:failed_when: and changed_when: are always templated and we should avoid adding {{}}.
    In other cases except when clause we have to use brackets, otherwise distinguish between an undefined variable and String will be very difficult.

    12. How do i generate Crypted Passwords for the User Module?

    A normal mkpasswd utility which is available in a normal Linux system is a great option for generating crypted passwords.
    mkpasswd –method=sha-512
    Is somehow this utility not available in our system, suppose we are using OS X, then also we can easily generate this password by using Python. But for the same, we need to install the Passlib password hashing library in our system.
    Once it installed, execute command will generate SHA512 password values.
    python -c “from passlib.hash import sha512_crypt; import getpass; print sha512_crypt.encrypt(getpass.getpass())”

    13. What is the best way to make Content Reusable/ Redistributable?

    There have 3 ways to reuse files in playbooks of Ansible. 3 ways include imports and roles.
    Include and Imports are actually helping to create multiple small files of a large playbook or break up a large playbook of multiple small files. Those small files can be used across multiple parent playbooks or even multiple times within the same playbook.
    Roles are mainly used to manage multiple tasks in a package together. It can include variables, handlers, or even modules and other plugins. Roles also can be uploaded and shared by Ansible Galaxy.

    14. How do i copy files recursively onto a Target Host?

    The copy module of Ansible has a recursive parameter. But most efficient to use synchronize module which wraps rsync. For the synchronize module we can use below command:
    -name: Copy over h5bp configuration
    synchronize: mode=pull src=/tmp/server-configs-nginx/{{ item }} dest=/etc/nginx/{{ item }}
    with_items:
    – “mime. types”
    – “h5bp/”
    To copy remote to remote use the same command, as delegate_to (as remote source) and current inventory_host (as remote dest).

    15. Speaking of tags, how do you filter out tasks?

    You can filter out tasks in one of two ways:

    • Use –tags or –skip-tags options on the command line
    • If you’re in Ansible configuration settings, use the TAGS_RUN and TAGS_SKIP options.

    16. What’s a handler?

    In Ansible, a handler is similar to a regular task in a playbook, but it will only run if a task alerts the handler. Handlers are automatically loaded by roles/<role_name>/handlers/main.yaml. Handlers will run once, after all of the tasks are completed in a particular play.

    17. How do you upgrade Ansible?

    Upgrading Ansible is easy. Just use this command: sudo pip install ansible==<version-number>

    18. When do you use {{ }}?

    One of Ansible’s most basic rules is: “Always use {{ }} except when:”

    19. Explain how to access shell environment variables.

    You can access the controlling machine’s existing variables by using the “env” lookup plugin. For instance, to access the value of the management machine’s home environment variable, you’d enter:

    local_home:”{{lookup(‘env’,’HOME’)}}”

    20. What is “idempotency”?

    idempotency is an important Ansible feature. It prevents unnecessary changes in the managed hosts. With idempotency, you can execute one or more tasks on a server as many times as you need to, but it won’t change anything that’s already been modified and is working correctly. To put it in basic terms, the only changes added are the ones needed and not already in place.

    Conclusion:

    Still, thinking of skipping Ansible? Well, do it at your own risk then, since it’s just a trailer. To pursue a full-on DevOps character, you need to have hands-on practice of Ansible as well. Wonder how you can acquire that? Join Our DevOps training sessions and let the experts teach you!

    SOURCES :

    • novelvista.com
    • educba.com

     

    2,500 points
    9 2