Section 3 Flashcards

1
Q

Look up ansible modules for ping
what is the url for module info?
show documentation for ping
locate the file for the ping module and view it
show how to use parameters in a playbook - basically just use a command that just shows how to do things with the module.

A

ansible-doc -l | grep ping
docs.ansible.com
ansible-doc ping
grab the file location and go there
ansible-doc -s ping

FOR URL
quick links (On Right)
Ansible Package Docs Home or choose modules and plugins index

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

Create a script that can be run just by its name that installs the latest httpd version on all managed nodes, and starts and enables the service

A

!/bin/bash

cd /usr/local/bin
vi setup.sh

ansible all -m dnf -a ‘name=httpd state=present’
ansible all -m service -a ‘name=httpd state=started enabled=yes’

chmod +x ./setup.sh

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

What does gathering facts mean?

A

This checks the servers current config and settings

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

Create a playbook to install vsftpd then start and enable the service, lastly copy ‘welcome to the ftp server’ in /var/ftp/pub/README. The permissions should be 0444. Make it to where the files won’t be transferred if the file and text already exist.

A
  • name: Install and start httpd services
    hosts: all
    tasks:
    • name: Install vsftpd
      yum:
      name: vsftpd
      state: latest
    • name:
      service:
      name: vsftpd
      state: started
      enabled: yes
    • name:
      copy:
      content: ‘Welcome to the FTP server/n’
      dest: /var/ftp/pub/README
      force: no
      mode: 0444


ansbile-playbook ask-become-pass this.yml

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

Create a list of services to install. Can you do the same with their services?

A

You can’t make a list for the services.

  • name: using lists
    hosts: all
    tasks:
    • name: Install Packages
      yum:
      name:
      • httpd
      • vsftpd
      • nmap
        state: lateset
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How would you write multiline strings on your playbook?
One should follow all of your indentation
The other should go as single string but allow you to write it multiline in the playbook for readability

A

>

  • for lines that won’t follow your indentation

- multilines that follow your indentation

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

Check that your playbook doesn’t have any mistakes

Perform a dry run on your playbook

A

ansible-playbook –syntax-check this.yml

ansible-playbook -C this.yml
or
ansible-playbook –check this.yml

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

Create two tasks in a playbook:
One creates a multiline string that follows indentation when ran
The other will be a single line but written in the playbook with multiple lines.

Check via ad-hoc commands that these files exist and show their contents

A
  • name: Copy multiline text
    hosts: ansible1
    tasks:
    • name: Copy text
      copy:
      content: |
      line1
      line2
      dest: /tmp/multiline.txt
    • name: copy more text
      copy:
      content: >
      line1
      line2
      dest: /tmp/multiline2

ansible ansible1 -a ‘cat /tmp/multiline.txt’

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

Why would you use multiple plays

A

A play is for a group of servers.
So one would be for web_servers while the next would be for db_servers

You can also set different connectivity options like become and remote_user

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

Create two plays in the same playbook
One for Installing and starting httpd, the other should test web site accessibility. The second play here should use the localhost so you can test if you can connect to the website from the control node.

You may need to cut and copy with vim

A
  • name: Install and Start HTTPD
    hosts: ansible2
    tasks:
    • name: Install HTTPD
      yum:
      name: httpd
      state: latest
    • name: Start HTTPD
      service:
      name: httpd
      state: started
      enabled: yes
    • name: Open port 80
      firewalld:
      service: http
      state: enabled
      permanent: True
    • name: Restart Firewalld
      service:
      name: firewalld
      state: restarted
  • name: Test HTTPD accessability
    hosts: localhost
    tasks:
    • name:
      uri:
      url: http://ansible2

3yy - copy three lines
p - paste

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

The ansible-playbook command allows you to increase verbosity. What are the levels of verbosity and what do they mean?

A

ansible-playbook -v test.yml

v - show task results
vv - tas results and task config
vvv - task results, task config, and info about connection to managed hosts
vvvv - *, verbosity about connection plug-ins, user accounts, and scripts that have been executed

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

Playbook
- play_one
- install httpd and firewalld
- add welcome page to httpd
- start firewalld and httpd
- enable httpd on firewall
- restart firewall
play_two
- test the conectivity of the webpage, show the content of the page, status code 200 will give you a success

A
  • name: Install and Start HTTPD
    hosts: ansible2
    tasks:
    • name: Install HTTPD
      yum:
      name: httpd
      state: latest
    • name: Start HTTPD
      service:
      name: httpd
      state: started
      enabled: yes
    • name: Open port 80
      firewalld:
      service: http
      state: enabled
      permanent: True
    • name: Restart Firewalld
      service:
      name: firewalld
      state: restarted
  • name: Test HTTPD accessability
    hosts: localhost
    tasks:
    • name:
      uri:
      url: http://ansible2
      return_content: yes
      status_code: 200

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

Using variables, create a user named ‘Lisa’ the name of the task should contain the variable as well as an ANSIBLE FACT that shows the hostname of the machine you’re running the playbook on.
What are ansible facts?

A
  • name: Add Users
    hosts: ansible1
    vars:
    users: lisa
    tasks:
    • name: Create user {{ users }} on host {{ ansible_hostname }}
      user:
      name: “{{ users }}”

FACTS - automatically set variables.

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

What are the three types of variables

A

fact - discovered by ansible that contains values describing specific system properties. These are discoverd when ansible executes on a remote system.
- system facts
- custom facts (you make them)
variable - Variable defined at the discretion of the user

magic variable - System variable that is automatically set

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

Show all Ansible facts

What does the argument for your module do in this case?

A
  • name: Fact Collection
    hosts: all
    tasks:
    • name: Show All Facts
      debug:
      var: ansible_facts

var prints variables. This is one of the few instances that you don’t have to put the var in curly brackets and quotes

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

In ansible_facts, there is the below dictionary. I want to grab the ip address here. What are the two ways to perform this.

    "default_ipv4": {
        "address": "192.168.10.198",
        "alias": "ens33",
        "broadcast": "192.168.10.255",
        "gateway": "192.168.10.2",
        "interface": "ens33",
        "macaddress": "00:0c:29:82:90:d3",
        "mtu": 1500,
        "netmask": "255.255.255.0",
        "network": "192.168.10.0",
        "prefix": "24",
        "type": "ether"
A

ansible_facts[‘default_ipv4’][‘address’]

or

ansible_facts.default_ipv4.address

17
Q

How would you print your ansible configuration?
How would you show only the configuration parts that are being implemented? If there is something that doesn’t show up here there might be a typo.
How do you show all the collections you currently have?
How do you install a collection

A

ansible-config view
ansible-config dump –only-changed
ansible-galaxy collection list
ansible-galaxy collection install this.collection