Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 15

Ansible Interview Questions -

1. What is an inventory file used for and default inventory host location?
Purpose: An inventory file contains a list of managed nodes (hosts) that Ansible
can connect to and work with. It defines how Ansible groups hosts together for
targeted actions.
Default Location: /etc/ansible/hosts

2. What is ansible configuration file used for and its default path?
Purpose: The Ansible configuration file lets you customize Ansible's behavior, such
as inventory locations, default modules to use, connection settings, and more.
Default Path: /etc/ansible/ansible.cfg

3. Do you write your inventory file?


Yes. Ansible inventory files are essential for organizing your hosts and defining
how Ansible will interact with them.

4. How many types of variables and precedence?


Types: There are many types of variables in Ansible (group vars, host vars, role
defaults, etc.).
Precedence It's important to understand variable precedence to avoid unexpected
behavior. A general rule of thumb is that more specific variables override more
general ones. There's a detailed list of precedence in the Ansible documentation:
[invalid URL removed]

5. Write the command to find the Python version on nodes


Code snippet
- name: Check Python version
shell: python --version
register: python_check

- name: Print Python version (if successful)


debug:
var: python_check.stdout

6. What is the file structure of Ansible roles?


Ansible roles follow a standard directory structure for organization:
tasks/: Contains the main tasks to be executed.
handlers/: Contains handlers (tasks triggered by notifications).
defaults/: Contains default values for variables.
vars/: Contains variables for the role.
files/: Contains files to be copied to the target hosts.
templates/: Contains templates for generating configuration files.
meta/: Contains metadata for the role.

7. What happens when one node or instance is unreachable?


Ansible will mark tasks for that host as "unreachable" and skip them.
The playbook might continue with other hosts if possible or fail entirely depending
on your error handling settings.

8. What happens when one task is failed in the playbook?


By default, Ansible will stop executing the playbook for the hosts where the task
failed.
You can adjust this behavior using error handling mechanisms like ignore_errors or
failed_when.

9. I have 20 servers, I want to install one package in 5 servers and another


package in the next 5 servers...like that. How to write an Ansible script for that…
Explain?
Code snippet
- hosts: group1[0:4] # Targets first 5 hosts in 'group1'
tasks:
- name: Install package A
apt:
name: package_a
state: present

- hosts: group1[5:9] # Targets next 5 hosts in 'group1'


tasks:
- name: Install package B
apt:
name: package_b
state: present

You'd need groups defined in your inventory file (e.g., 'group1').

10. What is the architecture of Ansible?


Master-Slave Model (Push-Based): Ansible has a control node (your machine) that
pushes configuration changes to managed nodes.
Agentless: Ansible doesn't need agents installed on managed nodes, primarily using
SSH for communication.
Configuration as Code: Playbooks use YAML for a simple, declarative way to define
tasks.

11. How do I supply variables while executing the playbook in Ansible?


There are several ways:

Command Line (-e flag): ansible-playbook playbook.yml -e "my_var=value"


Variables File: Create a separate YAML file and include it with the --extra-vars or
-e flag (ansible-playbook playbook.yml -e @vars.yml)
Prompts with vars_prompt: Have the playbook ask for the variable value when it
runs.

12. Explain about tags in Ansible?


Selective Execution: Tags let you assign labels to tasks or plays within a
playbook.
Running subsets: You can run specific tagged tasks using the --tags or --skip-tags
options with ansible-playbook.
Example: tasks: [ - name: Install Apache tags: ['webserver'] ]

13. How to execute a failed playbook again?


There isn't a built-in way to automatically rerun failed playbooks. Here are some
strategies:

Rerun from the failed task: Use Ansible's --start-at-task option to restart the
playbook at the point of failure.
External Scripting: Write a shell script or use a workflow management tool to
monitor Ansible runs and trigger reruns if needed.
Error Handling: Utilize Ansible's error handling mechanisms (rescue, block) within
your playbook to gracefully manage failures and potentially retry or self-
remediate.

14. How is Ansible different than other configuration management tools?


Simplicity: Ansible focuses on being easy to learn and use. Its YAML playbooks are
human-readable.
Agentless: No need to install agents on managed nodes, reducing overhead.
Idempotency: Ansible modules aim to be idempotent (safely repeatable for desired
state).
Push-Based: Primarily pushes changes from the control node, but there's also
Ansible Pull for specific use cases.

15. Ansible playbooks are written in what format?


YAML (YAML Ain't Markup Language). YAML is a huma;n-friendly data serialization
format focused on readability.

16. What is a module in Ansible?


Self-Contained Units: Modules are prewritten units of code that Ansible executes on
managed nodes to perform tasks (install packages, manage files, etc.)
Abstraction: They abstract away the details of how to perform actions, letting you
focus on the "what" rather than the "how".
Large Collection: Ansible has a vast library of built-in modules.

17. What is inventory used for in Ansible?


Host List: An inventory file lists the managed nodes Ansible can interact with.
Grouping: It allows you to group hosts logically (e.g., by OS, role, location) for
targeted actions.
Variables: You can associate variables with individual hosts or groups within the
inventory.

18. Name three places where Ansible variables can be stored?


Playbooks: Within the playbook itself.
Inventory Files: At the host or group level.
External Variable Files: Included in the playbook using vars_files.

19. What type of connection does Ansible establish with Linux and Windows nodes?
Linux: Primarily SSH (Secure Shell) by default.
Windows: WinRM (Windows Remote Management) for remote PowerShell execution.

20. Difference between remote and local execution in Ansible.


Remote Execution: This is most common. Tasks are executed on managed nodes defined
in your inventory.
Local Execution (local_action): For tasks you want executed directly on your
control node. Example: working with local files.

21. What is the purpose and location of the ansible.cfg file?


Purpose: The Ansible configuration file (ansible.cfg) allows you to customize
Ansible's default behavior. It controls settings like:
Location of inventory files
Modules to use by default
Connection parameters
Behavior for handling errors, forks, and much more.
Default Location: /etc/ansible/ansible.cfg

22. Name any two settings from the ansible.cfg file.


Here are two commonly used settings:
inventory: Specifies the path to your inventory file.
forks: Controls how many hosts Ansible will manage in parallel (defaults to 5).

23. Please write below a sample inventory file with host, group & group of groups
syntax in it.
Ini, TOML
# Simple 'hosts' file, can be INI or YAML format
[webservers]
webhost1.example.com
webhost2.example.com

[databases]
dbhost1.example.com

[development:children] # Group of groups


webservers
databases

24. What is the difference between group_vars & host_vars directories?


Both directories are used to store Ansible variables, but the scope is different:

group_vars: Variables defined in this directory apply to all hosts within a


specific group. Each group can have its own group_vars directory.
host_vars: Variables defined in this directory apply to a specific individual host.
Each host can have its own host_vars directory.

25. What are ad-hoc commands used for & write below the syntax of an ad-hoc
command?
Purpose: Ad-hoc commands execute single, quick tasks across managed nodes. It's
great for one-off actions without creating full playbooks.
Syntax: ansible <group or host pattern> -m <module_name> -a "<module arguments>"

26. Write below ad-hoc command to gather fact variables on all the hosts from the
inventory file?
Bash
ansible all -m setup

27. What format does ansible ad-hoc command return the output?
Ansible ad-hoc commands typically return output in JSON format by default.

28. Name three types of modules in ansible?


Core Modules: The essential modules bundled with Ansible itself (e.g., copy, file,
user).
Extra Modules: Additional modules that extend Ansible's functionality for specific
tasks (e.g., docker_container, cloudformation, yum).
Custom Modules: Modules you write yourself for tailored functionality to your
environment.

29. Name any 10 modules in Ansible that you have used.


This list will vary depending on your experience. Here's a possible sample of
commonly used modules:

copy: Copy files between the control node and managed nodes.
file: Manage file properties (state, permissions, ownership).
lineinfile: Modify single lines within files.
apt/yum: Manage packages on Debian/RedHat based Linux systems.
user: Manage user accounts.
group: Manage groups.
service: Manage services (start, stop, restart).
shell/command: Execute arbitrary shell commands on managed nodes.
template: Generate files from templates (powered by Jinja2).
synchronize: Use rsync for efficient file transfer.

30. How to list all the Ansible core modules from the command line.
Bash
ansible-doc -t module -l

31. How to display all the options/attributes for the apt module from the command
line.
Use the ansible-doc command:
Bash
ansible-doc apt
Use code with caution.
This will provide detailed information on the apt module, including available
options, explanations, and examples.

32. How can you check mandatory options for any module from the command line?
The ansible-doc output will indicate if a module's options are mandatory. Look for
the following:

required: true The option is mandatory.


required: false, or the absence of the 'required' field indicates the option is not
mandatory.

33. What is the setup module used for?


The setup module is a core Ansible module that gathers facts about managed nodes.
This includes:

Operating system information


Network interfaces
Hardware details
Python version
And many other system properties
You often run it as an early task in playbooks to make these gathered facts
available as variables.

34. Write down a sample global play declaration


Here's a basic global play in a playbook:

YAML
---
- hosts: all # Target all hosts in inventory
gather_facts: yes # Gather facts before tasks
become: yes # Execute tasks with elevated privileges

tasks:
# Your tasks go here

35. Write down any two tasks from a playbook with their proper format and names.
YAML
- name: Update system packages
apt:
name: "*" # Install all available updates
state: latest

- name: Ensure Apache is running


service:
name: apache2
state: started

36. What is the difference between sudo and become modules and their purpose?
Both are used for privilege escalation within Ansible, but they have key
differences:

sudo:
Runs commands as the 'sudo' user.
Useful if your Ansible user has general sudo permissions.
become:
Offers greater flexibility for different privilege escalation methods (sudo, su,
etc.).
Allows you to become a user other than root if needed.

37. Write down playbook syntax of starting ntp service on webserver and dbservers
host group at once.
YAML
- hosts: webservers:dbservers # Target multiple groups
become: yes

tasks:
- name: Start NTP service
service:
name: ntpd
state: started
enabled: yes

38. How to take user input from a playbook?


Use the vars_prompt module:

YAML
- vars_prompt:
- name: "db_password"
prompt: "Enter the database password"
private: yes # Don't display the input on screen

39. What is the debug module used for in playbooks?


The debug module is primarily for printing variable values or custom messages
during playbook execution. It aids in:

Troubleshooting issues.
Understanding the value of variables at specific points.

40. How to store the output of any task into a variable from a playbook?
Use the register keyword:

YAML
- name: Get disk usage
shell: df -h
register: disk_usage

- name: Print disk usage output


debug:
var: disk_usage.stdout

41. What are handlers used for in Ansible and how are they different from tasks?
Handlers: Special tasks that execute only when they're notified by other tasks.
Triggers: Handlers are triggered when a task changes the state of the system (e.g.,
install a package, modify a file).
Differences from tasks:
Handlers normally run at the end of a play, not immediately.
They run only if they've been notified.

42. Conditional execution in Ansible is used for what purpose and write down its
syntax with a small description?
Purpose: Conditionals (when) allow you to control whether tasks execute based on
specific conditions (like the presence of a file, a variable's value, etc.).
Syntax
YAML
- name: Install Apache if it's not present
apt:
name: apache2
state: latest
when: ansible_facts['packages']['apache2'] is not defined

43. What are templates used for and their format?


Purpose: Templates let you dynamically generate configuration files based on
variables and conditionals.
Format: Templates typically use the Jinja2 templating language, which is integrated
into Ansible.
Syntax (myconfig.conf.j2):
server_ip: {{ webserver_ip }}
{% if database_backend == 'mysql' %}
database_port: 3306
{% else %}
database_port: 5432
{% endif %}

44. What are Ansible roles and their purpose?


Self-Contained Units: Roles provide a structured way to organize playbooks, tasks,
variables, and other Ansible components for modularity and reuse.
Purpose:
Break down complex configurations into manageable, reusable units.
Promote code sharing and best practices within teams.

45. Command to generate Ansible roles directory structure.


Use the ansible-galaxy command:

Bash
ansible-galaxy init <role_name>

46. Name 5 directories from Ansible roles.


defaults: Contains default variables for the role.
files: Stores static files to copy to managed nodes.
handlers: Contains handlers for the role.
meta: Contains metadata about the role (dependencies, etc.).
tasks: Contains the main tasks for the role.

47. What are {{ }} symbols used for in Ansible?


The {{ }} symbols denote Jinja2 expressions within Ansible playbooks and templates.
They are used for:

Variable Substitution: Print the value of variables (e.g.,


{{ webserver_hostname }})
Basic control structures: In templates for elements like loops and conditionals.

48. Write down all the places where we can define variables according to their
precedence.
Ansible has a complex variable precedence order. Here's a general overview from
lowest to highest priority:

Extra vars (-e on the command line)


Inventory group variable files
Inventory host variable files
Playbook role defaults
Playbook role variables
Playbook included variables
Playbook facts
And many more!
It's best to refer to the official Ansible documentation for the full precedence
list.

49. Write down the syntax of a dictionary variable?


YAML
my_dict:
key1: value1
key2:
- item1
- item2
key3: true

50. Setup module gets executed after executing any ad-hoc command. (True or False)
True. The setup module is a special case. While ad-hoc commands usually target a
single task, ansible <pattern> -m setup automatically runs the setup module to
gather facts.

51. Ansible playbooks are written in XML format.


False. Ansible playbooks are written in YAML format.

52. ansible.cfg file is a list of plays.


False. The ansible.cfg file contains configuration settings for Ansible, not a list
of plays.

53. Fact variables are generated by Ansible, and we do not need to create fact
variables.
True. The setup module automatically gathers facts about managed nodes, generating
variables available for use in your playbooks.

54. Ansible is written in Python language.


True. Ansible is primarily developed in Python.

55. Ansible works on a Master and client relationship, where ansible control server
package is installed on master, and ansible client package is installed on all the
clients.
False. Ansible is agentless. You primarily need Python and SSH access (or WinRM for
Windows) on managed nodes.

56. Ansible loop module is with_items.


True. The with_items module is the primary way to create loops in Ansible.

57. All the templates in Ansible roles have to be defined in the main.yml file
inside the templates directory.
False. While you can use main.yml in the templates directory, an Ansible role can
have multiple template files.

58. All the roles uploaded to the Ansible Galaxy website are written and owned by
Ansible Inc (the organization).
False. Ansible Galaxy is a community hub; anyone can contribute and share Ansible
roles.

59. Ansible can only get installed on Linux machines but can manage Linux and
Windows nodes.
False. Ansible can be installed on control nodes running Linux, macOS, or even
Windows (via WSL- Windows Subsystem for Linux).

60. Write an Ansible task that can copy the file to a remote location with the
ownership of Jboss?
YAML
- name: Copy file with Jboss ownership
copy:
src: /local/path/to/file.txt
dest: /remote/path/on/managed/nodes/
owner: Jboss
group: Jboss

61. What is a local action in Ansible?


Focus: local_action tasks are executed directly on the control node (the machine
where you're running Ansible) as opposed to being run on managed nodes.
Uses:
Interacting with resources local to your control node (e.g., manipulating files).
Executing commands on the control node for which there isn't a dedicated module.

62. What are roles in Ansible?


Modularization: Roles are a way to structure related tasks, files, variables, and
other Ansible components into reusable bundles.
Organization: They promote code organization, maintainability, and sharing. Think
of them as 'mini playbooks' specialized for specific tasks.

63. Write a playbook for the installation of Apache on Ubuntu and CentOS?
YAML
---
- name: Install Apache
hosts: all

tasks:
- name: Install Apache on Debian/Ubuntu systems
apt:
name: apache2
state: latest
when: ansible_os_family == 'Debian'

- name: Install Apache on Red Hat/CentOS systems


yum:
name: httpd
state: latest
when: ansible_os_family == 'RedHat'

64. How to create a role in Ansible?


Use ansible-galaxy: The recommended way: ansible-galaxy init <role_name> (This sets
up the directory structure)
Manually: If you prefer, create the necessary directories (defaults, tasks,
handlers, etc.) within a 'roles' directory.

65. Different types of inventories in Ansible?


Static Inventories:
INI format: Simple host and group definitions in an INI-style file
YAML format: Similar structure but expressed in YAML syntax
Dynamic Inventories:
Scripts/Executables: Can fetch lists of hosts from external sources (cloud
providers, CMDBs, etc.).
Ansible-provided Inventory Plugins: Pre-built plugins to integrate with various
systems.

66. If we want system information of a machine, how will we get the data with
Ansible like we use facter in Puppet?
The setup Module: Run ansible <host_pattern> -m setup to gather facts about remote
systems. Fact variables hold information like OS details, hostname, IP addresses,
and more. They are the Ansible equivalent of Facter.

67. In which language do we write playbooks in Ansible?


Playbooks in Ansible are written in YAML (YAML Ain't Markup Language).

68. Activity that we use with Ansibles or advantage/functionality/purpose of


Ansible using in your project?
Here are some key activities, advantages, and use cases:
Configuration Management: Enforce desired state, manage software installations,
updates, and configuration files.
Application Deployment: Automate application rollouts and updates.
Provisioning: Set up new servers (physical or virtual) with required software and
configurations.
Orchestration: Coordinate more complex, multi-step tasks across several systems.

69. How to launch an LDAP server using Ansible?


Several ways to approach this:

Dedicated LDAP Roles: Find prebuilt roles on Ansible Galaxy to install and
configure LDAP servers (search for roles tailored to your specific LDAP
implementation).
Tasks: Use Ansible modules like package, template, and service to install the LDAP
server package, configure it with templates, and manage the service.
Hybrid: Combine a role with some custom tasks for fine-grain configuration.

70. How Ansible works... and what are the playbooks written other than the basic
playbooks?
Core: Ansible connects to managed nodes using SSH (Linux) or WinRM (Windows) and
pushes small programs (modules) to execute tasks.
Advanced Playbooks: While you start with basic tasks, Ansible can be used for:
Complex Deployments: Rolling updates, blue/green deployments, etc.
CI/CD Integration: Part of automated deployment pipelines.
Network device configuration: Managing switches, routers, etc.
Virtually anything! Ansible's flexibility lets you tackle a vast range of
automation scenarios.

71. Automated Code Deployment with Jenkins and Ansible


Here's how you can integrate Jenkins and Ansible for this scenario:
Jenkins Job Setup:

Create a Jenkins job that triggers when a new build artifact is available (e.g.,
polling your source code repository).
Configure a build step to generate your code artifact.
Ansible Playbook:

Write an Ansible playbook with tasks to:


Connect to your app and web servers
(Optional) Stop any existing instances of the application.
Use the copy module to push the new code to the correct locations.
(Optional) Restart the application services or perform any post-update tasks.
Link Jenkins and Ansible:

Install the Ansible Plugin for Jenkins.


In your Jenkins job, add an Ansible Playbook build step.
Provide Ansible with required credentials (SSH keys or passwords, if necessary).

72. Self-Healing Automation with Ansible


This requires a combination of monitoring, Ansible, and potentially external tools:
Monitoring: You'll need a monitoring system (e.g., Nagios, Zabbix) to detect if the
app crashes.
Trigger: The monitoring system should trigger an alert, which can execute an
Ansible playbook.
Playbook Actions:
Attempt to gracefully restart the app itself.
If a restart fails, provision a new server instance (if applicable) and deploy a
fresh copy of the app.
Send out notifications about the incident.

73. Playbook Example


Here's a simple playbook that installs Apache and creates a basic HTML page. Let me
know if you'd like to explore more complex scenarios!

YAML
---
- name: Install Apache and deploy sample website
hosts: webservers

tasks:
- name: Install Apache (Debian/Ubuntu)
apt:
name: apache2
state: latest
when: ansible_os_family == 'Debian'

- name: Install Apache (RedHat/CentOS)


yum:
name: httpd
state: latest
when: ansible_os_family == 'RedHat'

- name: Create a simple index.html file


copy:
content: "<h1>Ansible Demo</h1>"
dest: /var/www/html/index.html # May vary depending on your setup

74. What is a dynamic inventory in Ansible?


Real-Time Updates: A dynamic inventory gets its list of hosts from an external
source (like a cloud provider, CMDB, custom script).
Advantage: Your inventory reflects the current state of your infrastructure,
especially in environments where nodes are frequently added or removed.

75. How can you manage cloud services with Ansible?


Ansible has modules for interacting with popular cloud providers:

AWS: Modules for EC2 instances, S3, security groups, etc.


Azure: Modules for virtual machines, resource groups, and more.
GCP: Modules for managing various Google Cloud services.
Many Others: Ansible supports a wide range of cloud platforms.

76. How can you protect sensitive data in Ansible?


Ansible Vault: Encrypt entire variables files or individual variables within
playbooks.
External Stores: Use secrets management systems like HashiCorp Vault and integrate
them with Ansible.
Avoid Hardcoding: Use variable prompts or secure external variable files instead of
plaintext in playbooks.
77. How can you save the output of module execution in Ansible?
Use the register keyword with your Ansible tasks:

YAML
- name: Get hostname
hostname:
name: my_hostname
register: hostname_output

- name: Print hostname


debug:
var: hostname_output.stdout # Access the registered output

78. How can you manage error handling in Ansible?


ignore_errors: Let tasks continue even if one fails, good for non-critical
operations.
block/rescue: Define alternative steps in case of errors, useful for recovery.
failed_when: Create custom conditions for marking tasks as failed.

79. What are conditionals in Ansible?


Conditionals (using when) let you control if tasks execute based on criteria like:

Variables values
Existence of files
Output of previous tasks

80. Write a playbook to create an AMI on AWS


You'll need the amazon.aws module collection. Here's a basic example (ensure you
set AWS credentials securely):

YAML
- name: Create AMI
hosts: localhost
connection: local
gather_facts: false

tasks:
- name: Create AMI
amazon.aws.ec2_ami:
instance_id: your_instance_id
name: my_ami_{{ ansible_date_time.iso8601 }}
wait: yes

81. How can you access fact variables in Ansible?


Fact variables gathered by the setup module become available like any other
variable. Here's how to use them:

Directly in playbooks: {{ ansible_facts['hostname'] }}


In templates (Jinja2): Same as above, for dynamically generated files.
In conditional statements: when: ansible_facts['os_family'] == 'Debian'

82. Can we create an Ansible module?


Yes, you can create custom Ansible modules! Here's how:

Python: Most Ansible modules are written in Python. You'll need to understand how
to structure the module and handle arguments.
Plugins: Ansible provides a plugin system where you can develop modules in other
languages, though Python is most common.
83. How can you do provisioning with Ansible?
Ansible is excellent for provisioning new servers or instances:

Cloud Modules: Utilize Ansible's cloud modules (e.g., for AWS, Azure, GCP) to
provision instances.
Installation Tasks: Include tasks to install necessary packages, configure
software, etc.
Idempotency: Ansible helps ensure your provisioning playbooks are safe to re-run
for consistent setups.

84. Bash vs. Python vs. Configuration Management Tools


Each has its strengths:

Bash:
Quick-and-dirty scripts
Procedural – good for linear tasks
Python:
More structured, libraries and modules
Handles complex logic and data manipulation
Ansible (and similar):
Declarative – focus on desired state
Modules and idempotency simplify configuration
Great for larger-scale orchestration and standardization

85. How can you update a single table in a database with Ansible?
Ansible has database modules:

mysql_db: For MySQL/MariaDB interactions.


postgresql_db: For PostgreSQL interactions.
Others for different database systems
Example (MySQL):

YAML
- name: Update a database table
mysql_db:
login_user: dbuser
login_password: dbpassword
name: mydatabase
state: present
sql: "UPDATE mytable SET column1='new_value' WHERE id=123"

86. What types of roles did you use in your playbook? Explain.

Base role: Core OS configurations (packages, security hardening).


Application roles: Installing and configuring specific apps (Apache, Nginx, Tomcat,
database, etc.).
Infrastructure roles: Managing cloud resources, network devices.

87. How to create and use a dynamic inventory?


Choose a method:

Script/Executable: Write a script (Python is common) that fetches host information


and outputs it in JSON format.
Inventory Plugins: Ansible has built-in plugins for many cloud providers and CMDBs.
Reference in Playbook: Make sure Ansible can find your inventory script. Set the
inventory property in your ansible.cfg or use command-line options to point to your
script.

88. Write a playbook for installing AppDynamics and configuring the agents for the
same?
I'd need more specifics, but here's the general outline:
Assumptions:

Target OS is supported by AppDynamics


You have the installation files/URLs
You have configuration parameters
Playbook:

YAML
- name: Install and configure AppDynamics
hosts: my_servers

vars:
appd_agent_version: ...
appd_controller_host: ...
# ...other configuration params

tasks:
- name: Download AppDynamics agent
get_url:
url: https://download.appdynamics.com/agent/...{{ appd_agent_version }}...
dest: /tmp/appd_agent.zip

- name: Install AppDynamics agent


become: true
unarchive:
src: /tmp/appd_agent.zip
dest: /opt
remote_src: yes

- name: Configure AppDynamics agent


template:
src: appd_agent.conf.j2
dest: /opt/appdynamics/config/app-agent-config.xml

Important:
Replace placeholders with accurate values.
May need additional tasks (dependencies, firewall rules, agent start, etc.).

To check modules = ansible-doc -t module -l


To learn specific module = ansible-doc <modulename>

89. Describe each of the following components in Ansible, including the


relationship between them:
Task
Module
Play
Playbook
Role

Task – a call to a specific Ansible module Module – the actual unit of code
executed by Ansible on your own host or a remote host. Modules are indexed by
category (database, file, network, …) and also referred to as task plugins.
Play – One or more tasks executed on a given host(s)
Playbook – One or more plays. Each play can be executed on the same or different
hosts
Role – Ansible roles allows you to group resources based on certain
functionality/service such that they can be easily reused. In a role, you have
directories for variables, defaults, files, templates, handlers, tasks, and
metadata. You can then use the role by simply specifying it in your playbook.

90. How Ansible is different from other Automation tools?


Ansible is:
Agentless
Minimal run requirements (Python & SSH) and simple to use
Default mode is "push" (it supports also pull)
Focus on simpleness and ease-of-use

Variables -
In the play = vars:
In the play = vars_files:
On the command line = -e key=value
Using vars_prompt: to request values from user while running playbook
Ansible vault
(1a) Create encrypted file:
$ ansible-vault create <FILENAME>
$ ansible-vault create --vault-password-file=.secret_file <FILENAME>
(2a) Enter and confirm new vault password
(1b) Or encrypt and existing file(s):
$ ansible-vault encrypt <FILE1> <FILE2> ...
$ ansible-vault encrypt --output=NEW_FILE <OLDFILE>
(2b) Enter and confirm new vault password
(3) View file:
$ ansible-vault view <FILENAME>
(4) Edit file:
$ ansible-vault edit <FILENAME>
(5) Change password:
$ ansible-vault rekey <FILENAME1> <FILENAME2>
$ ansible-vault rekey --new-vault-password-file=.secret_file <FILENAME>
(6) Decrypt file:
$ ansible-vault decrypt <FILENAME> --output=<FILENAME>

You might also like