Section 10 Flashcards

1
Q

What does assert do?

A

Performs conditional action
Works with ‘that’ which defines a list of conditionals

If any conditional is false the task fails

Uses ‘success_msg’ and ‘fail_msg’

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

Have the playbook request the user to create a variable named filesize. You should specify the user types in a file size in megabytes

Use assert to check if the filesize is less than or equal to 100 or greater than or equal to 1
use an escape character in one of your messages

Next create a zeroed out file of that size

Assert fails a task, which means it will actually still try the task on all servers even if one fails

A

vars_prompt:
- name: filesize
prompt: “your message here”

tasks

assert:
that:
- “( filesize | int ) <= 100 }}”
- “( filesize | int ) >= 1 }}”
fail_msg: “fail's escape character”
success_msg: “”

  • name: create a file
    command: dd if=/dev/zero of=/bigfile bs=1 count={{ filesize }}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Create a file that checks if vgdata exists

use assert to print a fail and success message depending on that conditional

A

Example at 271

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

What is a tag?

A

A label that is applied to a task or another item like a block or play

You can utilize your tags by specifying what you want with your ansible-playbook command

The below will run the tags you ask or skip the ones your request
ansible-playbook –tags

ansible-playbook –skip-tags

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

Create a playbook that uses tags

Next only run one of the tagged tasks

A

debug:
msg: One
tags:
- debug

dnf:
name: httpd
state: latest
tags:
- install

ansible-playbook –tags “install”

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

Can tags be used for included or imported tasks?

A

only static not dynamic
so this would work for import_tasks but not include_tasks
same with include_roles

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

Can you use the same tags for the different tasks?

A

Yes, this is best if you want to group tasks.

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

List all tasks in a playbook. Show all their tags as well

A

ansible-playbook –list-tags –list-tasks test.yml

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

Which tasks won’t be displayed via –list-tasks?

A

tasks inside block/rescue/always sections and dynamically and statically included tasks

import_tasks (static) will normally show up unless it’s in the block, rescue, or always section. Similarly, include_tasks (dynamic) won’t appear at all because it’s loaded at runtime.

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

What are special tags?
List them

A

They modify how the tag works.
These are premade tags. normally we wouldn’t use tagged and untagged because if a task has no tag ansible denotes that already with untagged, the opposite is true for tagged.

always - task always runs unless specified with –skip-tags always

never - Never runs a task unless otherwise specified

tagged - runs all tagged tasks

untagged - runs all untagged tasks

all - runs all tasks

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

How would you run two specific tagged tasks that contain either the tags ‘one’ or ‘two’?

A

ansible-playbook playbook.yml –tags one,two

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

You have a task with the tags never and debug.

how would you run tasks with these tags

A

ansible-playbook –tags all,debug
This runs everything but only executes tasks with the debug tag. The book says this will run debug and the rest of the tasks as well, so test these out.

–tags never,debug actively skips never tasks.

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

What does an ansible managed node need in order to use it?

A

ssh running
python installed
privilege escalation is setup
ssh-keys

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

Let’s say we have a managed node with multiple ips, but we only want to connect via 192.168.4.55.

how can we set this up in the ansible.cfg

A

ansible3.example.com ansible_host=192.168.4.55

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

What does the ping module actually do?

A

Checks ip connectivity
accessibility of the ssh service
sudo privilege escalation
and availability of the python stack (it makes sure python and its libraries are setup)

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

If you are having issues with privilege escalation, what might be the problem

A

Make sure ansible.cfg is setup correctly and specifies remote_user
ssh keys are setup
become is true
become_user is set to root
sudo is setup correctly on the managed node

17
Q

Create a playbook that removes ansible from the wheel group

reboot the node

Try to ping it to diagnose issues

make the user part of wheel again

ping the managed node once more

A

test.yml
user:
name: ansible
groups: ‘ ‘

ansible ansible3 -m reboot
ansible ansible3 -m raw -a “usermod -aG wheel ansible” -u root -k