Ansible
General 3 questions
- #1Ansible - My First Playbook
- Write a playbook that will:
a. Install the package zlib
b. Create the file
/tmp/some_file - Run the playbook on a remote host
- Write a playbook that will:
a. Install the package zlib
b. Create the file
- #2Ansible - My First Task
- Write a task to create the directory ‘/tmp/new_directory’
- #3Ansible - Update and upgrade APT packages task
- Write a task to update and upgrade apt packages
Ansible Self Assessment 48 questions
- #4Describe each of the following components in Ansible, including the relationship between them:
- Task
- Inventory
- Module
- Play
- Playbook
- Role
- Task
- #5How Ansible is different from other automation tools? (e.g. Chef, Puppet, etc.)
- #6True or False? Ansible follows the mutable infrastructure paradigm
- #7True or False? Ansible uses declarative style to describe the expected end state
- #8What kind of automation you wouldn't do with Ansible and why?
- #9How do you list all modules and how can you see details on a specific module?
- #10What is an inventory file and how do you define one?
- #11What is a dynamic inventory file? When you would use one?
- #12Modify the following task to use a variable instead of the value "zlib" and have "zlib" as the default in case the variable is not defined
- name: Install a package package: name: "zlib" state: present - #13How to make the variable "use_var" optional?
- name: Install a package package: name: "zlib" state: present use: "{{ use_var }}" - #14What would be the result of the following play?
- #15When the value '2017'' will be used in this case:
{{ lookup('env', 'BEST_YEAR') | default('2017', true) }}? - #16If the value of certain variable is 1, you would like to use the value "one", otherwise, use "two". How would you do it?
- #17The value of a certain variable you use is the string "True". You would like the value to be a boolean. How would you cast it?
- #18You want to run Ansible playbook only on specific minor version of your OS, how would you achieve that?
- #19What the "become" directive used for in Ansible?
- #20What are facts? How to see all the facts of a certain host?
- #21What would be the result of running the following task? How to fix it?
- hosts: localhost tasks: - name: Install zlib package: name: zlib state: present - #22Which Ansible best practices are you familiar with?. Name at least three
- #23Explain the directory layout of an Ansible role
- #24What 'blocks' are used for in Ansible?
- #25How do you handle errors in Ansible?
- #26You would like to run a certain command if a task fails. How would you achieve that?
- #27Write a playbook to install ‘zlib’ and ‘vim’ on all hosts if the file ‘/tmp/mario’ exists on the system.
- #28Write a single task that verifies all the files in files_list variable exist on the host
- #29Write a playbook to deploy the file ‘/tmp/system_info’ on all hosts except for controllers group, with the following content
- #30The variable 'whoami' defined in the following places:
- role defaults -> whoami: mario
- extra vars (variables you pass to Ansible CLI with -e) -> whoami: toad
- host facts -> whoami: luigi
- inventory variables (doesn’t matter which type) -> whoami: browser
According to variable precedence, which one will be used?
- role defaults -> whoami: mario
- #31For each of the following statements determine if it's true or false:
- A module is a collection of tasks
- It’s better to use shell or command instead of a specific module
- Host facts override play variables
- A role might include the following: vars, meta, and handlers
- Dynamic inventory is generated by extracting information from external sources
- It’s a best practice to use indentation of 2 spaces instead of 4
- ‘notify’ used to trigger handlers
- This “hosts: all:!controllers” means ‘run only on controllers group hosts
- A module is a collection of tasks
- #32Explain the Difference between Forks and Serial & Throttle.
- #33What is ansible-pull? How is it different from how ansible-playbook works?
- #34What is Ansible Vault?
- #35Demonstrate each of the following with Ansible:
- Conditionals
- Loops
- Conditionals
- #36What are filters? Do you have experience with writing filters?
- #37Write a filter to capitalize a string
- #38You would like to run a task only if previous task changed anything. How would you achieve that?
- #39What are callback plugins? What can you achieve by using callback plugins?
- #40What is the difference between
include_taskandimport_task? - #41File '/tmp/exercise' includes the following content
Goku = 9001 Vegeta = 5200 Trunks = 6000 Gotenks = 32With one task, switch the content to:
Goku = 9001 Vegeta = 250 Trunks = 40 Gotenks = 32 - #42True or False? By default, Ansible will execute all the tasks in play on a single host before proceeding to the next host
- #43What is a "strategy" in Ansible? What is the default strategy?
- #44What strategies are you familiar with in Ansible?
- #45What the serial keyword is used for?
- #46How do you test your Ansible based projects?
- #47What is Molecule? How does it works?
- #48You run Ansible tests and you get "idempotence test failed". What does it mean? Why idempotence is important?
- #49How to find out the data type of a certain variable in one of the playbooks?
- #50What are collections in Ansible?
- #51Why Use Ansible Collections?