Top 50 Ansible Basic Interview Questions and Answers

1. What is Ansible?


Ansible is an open-source automation tool used for IT tasks such as application deployment, configuration management, and orchestration.

2. What are the key features of Ansible?


Some key features of Ansible include easy installation, agentless architecture, declarative language for describing infrastructure, simple automation using YAML files, and support for Windows, Linux, and Unix environments.

3. How is Ansible different from other configuration management tools?


Unlike other configuration management tools, Ansible does not require a separate agent to be installed on target machines. It uses SSH or WinRM to connect to the target nodes and manage them remotely.

4. What are Ansible playbooks?


Ansible playbooks are files written in YAML format that define a set of tasks to be executed on remote machines. These playbooks describe the desired state of the infrastructure and Ansible ensures that the target machines are configured accordingly.

5. What is an Ansible inventory file?


An Ansible inventory file is a text file that contains a list of target machines or groups of machines that Ansible will manage. It can be a static file or a dynamic inventory script that fetches the inventory from an external source.

6. What are Ansible modules?


Ansible modules are small pieces of code written in Python, PowerShell, or other languages that perform specific actions on target machines. They help in managing configurations, executing commands, and handling other infrastructure tasks.

7. How do you install Ansible?


Ansible can be installed on Linux, Unix, or Windows machines. On Linux and Unix systems, it can be installed using package managers like apt or yum. On Windows, Ansible can be installed using pip or by downloading the Windows installer.

8. How do you define variables in Ansible?


Variables can be defined in Ansible playbooks using the 'vars' keyword. They can also be defined in separate variable files or passed as command-line arguments using the '-e' flag.

9. How do you create a playbook in Ansible?


To create a playbook in Ansible, you need to create a YAML file and define a list of tasks. Each task specifies the module to be used, the target hosts, and the parameters for the module.

10. How do you execute a playbook in Ansible?


To execute a playbook in Ansible, you use the 'ansible-playbook' command followed by the playbook file name. You can also specify the target hosts using the '-i' option.

11. How do you handle errors in Ansible?


You can handle errors in Ansible by using the 'ignore_errors' parameter in the task definition. This will allow the playbook to continue executing even if a task fails.

12. What is Ansible Galaxy?


Ansible Galaxy is a public repository of Ansible roles that can be used to easily share and reuse configurations and automation scripts. It includes a wide range of roles contributed by the Ansible community.

13. How do you handle sensitive data in Ansible?


Sensitive data such as passwords or API keys can be stored in Ansible Vault. Vault is a feature in Ansible that allows you to encrypt sensitive data using a password or key file.

14. What is the difference between playbook and role in Ansible?


A playbook is a YAML file that defines a set of tasks to be executed on target machines. A role, on the other hand, is a reusable set of tasks, variables, and files that can be easily included in multiple playbooks.

15. How do you debug Ansible playbooks?


Ansible provides various methods for debugging playbooks, such as using the 'debug' module to print variable values or using the '-vvv' option to enable verbose output during playbook execution.

16. How do you manage multiple environments using Ansible?


Multiple environments can be managed using Ansible by defining different inventory files for each environment and specifying the appropriate inventory file during playbook execution.

17. How do you handle differences between different operating systems using Ansible?


Ansible provides the 'when' keyword to conditionally execute tasks based on specific conditions. You can use the 'ansible_os_family' variable to handle differences between different operating systems.

18. How do you perform rolling updates using Ansible?


Rolling updates can be performed using Ansible by defining groups of hosts and using the 'serial' keyword to define the number of hosts to be updated simultaneously. Ansible will then perform the updates in a rolling fashion.

19. What is idempotence in Ansible?


Idempotence means that running the same Ansible playbook multiple times should have the same effect as running it once. Ansible ensures idempotence by only applying changes that are required to bring the target system into the desired state.

20. How do you integrate Ansible with version control systems?


Ansible can be integrated with version control systems like Git by storing playbooks, roles, and other Ansible artifacts in a Git repository. This allows for versioning, collaboration, and change tracking.

21. How do you perform conditional execution in Ansible?


Conditional execution in Ansible can be achieved using the 'when' keyword. You can specify a condition that needs to be satisfied for a task to be executed.

22. How do you manage secrets in Ansible?


Secrets can be managed in Ansible using the 'ansible-vault' command. It allows you to encrypt and decrypt sensitive data, making it secure during storage and transfer.

23. How do you manage environment-specific variables in Ansible?


Environment-specific variables can be managed in Ansible by using a combination of inventory variables and conditionals. You can define different variable values in different environments and use the 'when' keyword to conditionally override or use those variables.

24. How do you execute commands on target machines using Ansible?


Commands can be executed on target machines using the 'command' or 'shell' module in Ansible. You can specify the command to be executed and the target hosts.

25. What is the difference between a task and a role in Ansible?


A task is a single unit of work defined in an Ansible playbook, whereas a role is a collection of tasks, variables, and files that can be easily reused and shared across multiple playbooks.

26. How do you manage package installations using Ansible?


Package installations can be managed using the 'package' module in Ansible. You can specify the package name, state (present or absent), and other parameters.

27. How do you manage services using Ansible?


Services can be managed using the 'service' module in Ansible. You can specify the service name, state (started or stopped), and other parameters.

28. How do you manage files and directories using Ansible?


Files and directories can be managed using the 'file' module in Ansible. You can specify the path, state (present or absent), owner, permissions, and other parameters.

29. How do you manage configuration files using Ansible?


Configuration files can be managed using the 'template' module in Ansible. You can specify the source and destination paths, variables, and other parameters.

30. How do you manage users and groups using Ansible?


Users and groups can be managed using the 'user' and 'group' modules in Ansible. You can specify the user or group name, state (present or absent), password, and other parameters.

31. How do you manage SSH keys using Ansible?


SSH keys can be managed using the 'authorized_key' module in Ansible. You can specify the key, user, and other parameters.

32. How do you manage cron jobs using Ansible?


Cron jobs can be managed using the 'cron' module in Ansible. You can specify the cron schedule, command, user, and other parameters.

33. How do you manage firewalls using Ansible?


Firewalls can be managed using the 'ufw' or 'iptables' modules in Ansible. You can specify the rule, state (enabled or disabled), and other parameters.

34. How do you manage Docker containers using Ansible?


Docker containers can be managed using the 'docker_container' module in Ansible. You can specify the image, state (started or stopped), ports, volumes, and other parameters.

35. How do you manage Kubernetes using Ansible?


Kubernetes can be managed using the 'k8s' module in Ansible. You can specify the API version, kind, name, state (present or absent), and other parameters.

36. How do you manage Amazon Web Services (AWS) resources using Ansible?


AWS resources can be managed using the 'ec2' or 's3' modules in Ansible. You can specify the resource type, name, state (present or absent), and other parameters.

37. How do you manage network devices using Ansible?


Network devices can be managed using the 'ios_command' or 'nxos_command' modules in Ansible. You can specify the command, target device, username, password, and other parameters.

38. How do you manage VMware vSphere using Ansible?


VMware vSphere can be managed using the 'vmware_guest' module in Ansible. You can specify the vCenter server, username, password, virtual machine name, state (powered on or off), and other parameters.

39. How do you manage Azure resources using Ansible?


Azure resources can be managed using the 'azure_rm_resourcegroup' or 'azure_rm_virtualmachine' modules in Ansible. You can specify the resource group, virtual machine name, state (present or absent), and other parameters.

40. How do you manage GCP resources using Ansible?


GCP resources can be managed using the 'gcp_compute_instance' or 'gcp_compute_address' modules in Ansible. You can specify the project, zone, instance name, state (present or absent), and other parameters.

41. How do you manage OpenStack resources using Ansible?


OpenStack resources can be managed using the 'os_server' or 'os_volume' modules in Ansible. You can specify the authentication details, server or volume name, state (present or absent), and other parameters.

42. How do you manage Windows machines using Ansible?


Windows machines can be managed using the 'win_command' or 'win_shell' modules in Ansible. You can specify the command, target hostname, username, password, and other parameters.

43. How do you manage macOS machines using Ansible?


macOS machines can be managed using the 'shell' or 'command' modules in Ansible. You can specify the command, target hostname, username, password, and other parameters.

44. How do you manage network configurations using Ansible?


Network configurations can be managed using the 'ios_config' or 'eos_config' modules in Ansible. You can specify the configuration commands, target device, username, password, and other parameters.

45. How do you manage database configurations using Ansible?


Database configurations can be managed using the 'mysql_db' or 'postgresql_db' modules in Ansible. You can specify the database name, state (present or absent), username, password, and other parameters.

46. How do you manage web server configurations using Ansible?


Web server configurations can be managed using the 'apache2_module' or 'nginx_module' modules in Ansible. You can specify the module name, state (present or absent), and other parameters.

47. How do you manage load balancer configurations using Ansible?


Load balancer configurations can be managed using the 'bigip_command' or 'f5_command' modules in Ansible. You can specify the command, target device, username, password, and other parameters.

48. How do you manage cloud storage using Ansible?


Cloud storage can be managed using the 's3_bucket' or 'azure_rm_storageaccount' modules in Ansible. You can specify the bucket or storage account name, state (present or absent), and other parameters.

49. How do you manage container orchestration using Ansible?


Container orchestration can be managed using the 'k8s' or 'docker_swarm' modules in Ansible. You can specify the API version, kind, orchestration tool (Kubernetes or Docker Swarm), state (present or absent), and other parameters.

50. How do you manage secrets management systems using Ansible?


Secrets management systems can be managed using the 'ansible-vault' or 'hashivault' modules in Ansible. You can specify the secrets, encryption method, authentication details, and other parameters.

Comments