Final Exam Flashcards

1
Q

Writing a module, regardless of language, requires what minimal information in the output so Ansible can properly run the modules?

  1. {“changed”:,”output”:”string”}
  2. {}
  3. “changed”=true,output=”string”
  4. Ansible doesn’t need output from a module
A

(2) {}

Ansible requires a JSON dictionary to be returned. The minimum dictionary is an empty dictionary.

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

When specifying more than one conditional requirements for a task, what is the proper form?

  1. -when: foo == “hello” and bar == “world”
  2. -when: foo == “hello” && bar == “world”
  3. -when: foo is “hello” and bar is “world”
  4. -when: foo == “hello”
    - when: bar == “world”
A

-when: foo == “hello” and bar == “world”

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

What is the proper way of referencing a variables value in an Ansible task?

  1. ${variable_name}
  2. {variable_name}
  3. @variable_name
  4. ”{{variable_name}}”
A

(4) “{{variable_name}}”

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

How are variables referenced in an Ansible template

A

{{ variable }}

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

When running a playbook on remote target host you receive Python error similar to “[Error 13] Permission denied: ‘/home/nick/.ansible/tmp’.” What would be the most likely propblem?

  1. The user running ‘ansible-playbook’ must run it from their own directory
  2. The user’s home or .ansible directory on the Ansible remote host is not writeable by the user running the play
  3. The specified user does not exist on the remote system
  4. The user’s home or .ansible directory on the Ansible system is not writeable by the user running the play.
A

(2) The user’s home or .ansbl directory on the Ansible remote host is not writeable by the user running the play.

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

What ansible tool or method greatly enhances ability to reuse and share roles?

A

Ansible Galaxy: ansible-galaxy

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

In ansible, how can a task be run in “fire and forget” method?

  1. Use asnchronous mode but don’t poll the task
  2. Use shell to call a bash command and add ‘&’ to the end of the command
  3. Use asynchronous mode and set ‘async: 0’
  4. Use asynchronous mode and set ‘poll: 0’
A

Use asynchronous mode and set ‘poll: 0’

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

When using a role, where is the best location for setting default values for your variables?

  1. roles/vars/main.yml
  2. role/default/main.yml
  3. The master playbook
  4. Using –extra-vars on the command line
A

role/default/main.yml

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

How are roles called from a play?

  1. -roles:
  2. role:
  3. include:
  4. include: { role: }
A

-roles:

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

Which of the following is an invalid variable name in Ansible?

  1. host-first-ref
  2. Host1stRef
  3. host_first_ref
  4. host1st_ref
A

(1) host-first-ref

Valid variable names can contain only letters, numbers, and underscores

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

When writing an Ansible module using Python with the Ansible supplied helper module, what is the best way to return results to Ansible?

  1. Print json formatted output
  2. Using the JSON python module, use ‘json.dumps’ with a Python dictionary of results
  3. Write the results back to a file for Ansible to read in
  4. Use the exit_json and fail_json functions
A

Use the ‘exit_json’ and ‘fail_json’ functions.

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

Sometimes it is needed to call a roll dependency more than once. Ansible, by default, only calls a roll once unless the arguments are different. How can this be overridden in Ansible?

  1. Add ‘allow_duplicates: yes’ declarative in the playbook
  2. Add ‘run_always: yes’ declarative in the playbook
  3. This can not be overriden in Ansible
  4. Run the playbook with ‘–alow-duplicates’ on the command line
A

Add ‘allow_duplicates: yes’ declarative in the playbook.

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

How can Ansible be configured to invoke the interactive debugger when an error in the playbook is encountered?

  1. Set –debugger on the command line
  2. Set ‘strategy:debug’ in the play
  3. Call the debug module with parameter ‘interactive:true’
  4. Set ‘debugger: true’ in the play
A

(3) ‘strategy:debug’

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

Which resource can not be defined in an Ansible playbook?

  1. Fact Gathering State
  2. Inventory File
  3. Host Groups
  4. Variables
A

(2) Inventory File

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

Which of the following capabilities is not supported by Ansible Galaxy?

  1. Create filesystems structure for new roles
  2. Authenticate to Galaxy Hub for role development an management
  3. Manage existing roles
  4. Credential management
A

Ansible does not support

  • (4) Credential management
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

When writing custom Ansible modules, which language is not supported?

  1. All of the languages are supported
  2. Bash
  3. C++
  4. Python
A

All of the languages are supported?

17
Q

When not using Python with the Ansible library to write a module, how are parameters passed to the module

  1. They are stored in a predetermined sqlite db table which the module fetches from
  2. Only Python modules using the Ansible library can accept parameters
  3. They are in a file as key/value pairs with the filename and path passed as command line arguments
  4. They are passed as command line arguments
A

They are in a file as key/value pairs with filename and path passed as command line arguments

18
Q

Ansible provides some methods for controlling how or when a task is run. Which of the following is a valid method for controlling a task with a loop?

  1. -items:
  2. -with_items:
  3. -with:
  4. -only_when:
A

(2) -with_items:

19
Q

If Chris has a playbook that configures his MySQL server before creating users, databases and dumping data into it, the service needs to be restarted to pick up the new configuration. What is the best method available in Ansible to handle this?

  1. Use the ‘handler’ functionality Ansible provides by adding the ‘notify’ directive to the configuration play and creating a task in the handlers utilizing the ‘shell’ module to call ‘/etc/init.d/mysqld restart’.
  2. Use the ‘handler’ functionality Ansible provides by adding ‘notify’ directive to the configuration play and creating a task in the handlers section utilizing the ‘service’ module
  3. Create a play using the ‘service’ module immediately after the configuration play(s) to restart MySQL
  4. Create a play that uses ‘shell’ module and calls ‘/etc/init.d/mysqld restart’ immediately after the configuration play(s)
A

(2) Use the ‘handler’ functionality Ansible provides by adding ‘notify’ directive to the configuration play and creating a task in the handlers section utilizing the ‘service’ module

20
Q

Using the ansible tower api, what is the best way to sort query results?

A

Sorting can be done by passing this value in the request:

?order_by=

speficy field like this:

?order_by={{field}}

21
Q

An Ansible Template is capable of managing variables as well as loops and conditionals. What is the proper syntax to start and end a statement to be processed in a template?

  1. {{ }}
  2. {% %}
  3. ``
  4. $()
A

{{ }}

22
Q

With the advent of elastic environments it can be difficult to manage a static host list that accurately represents the environment that Ansible runs in. What mechanism does Ansible provide to cope with this?

  1. Ansible can’t manage elastic environments
  2. Plugins for elastic host scanning
  3. Inventory Groups
  4. Dynamic inventories
A

Dynamic inventories that can work with cloud providers, LDAP, Cobbler, and/or enterprise CMDB systems.

23
Q

When running playbooks, how can you test the playbook without actually running the playbook?

A

Use “check_mode: yes” in the playbook.

24
Q

When using Ansible, what is the proper best practice way to beging a playbook?

A

(three dashes)