Custom Modules Flashcards

1
Q

Provide command line for executing the script

can_reach www.example.com 80 1

Located under scripts/can_reach.sh

A
  • name: check if server is reachable

script: scripts/can_reach.sh www.example.com 80 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

In what folder does Ansible look for modules?

A

In the library directory relative to the playbook.

playbooks/library

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the 5 steps Ansible use to execute a module?

A

1) If the module is in Python, generate a python script with arguments
2) Copy the script over to the managed node
3) Create an argument file on the managed node (non-Python)
4) Invoke the module on the node, passing argument file
5) Parse the output of the module

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the possible formats for the arguments that Ansible passes to modules?

A

1) Key value (ex. host=db.example.com port=4545 timeout=1)

2) JSON

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

My module can_reach is written in bash. How would Ansible invoke it?

A

/path/to/can_reach

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the output format of Ansible modules?

A

JSON

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What variables does Ansible expect in the output of a module?

A

changed
failed
msg

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How does Ansible use the changed variable returned by modules?

A

to determine if some handlers should called

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How does Ansible use the failed variable returned by modules?

A

if failed=true, no further task will be executed on this host unless ignore_errors or failed_when is set.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you test your module?

A

use the test-module script in /hacking folder of ansible git repo.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Why is Python the prefered language for writing modules?

A

Because python provides helper code to faciliate your work and for creating good citizen modules.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you document a module written in python?

A

By declaring DOCUMENTATION and EXAMPLES variable at the top of the module source code file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you specify that your bash module expects json instead of key=value?

A

Add the comment #WANT_JSON at the top of the file after the language shebang.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly