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.
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
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
!/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
What does gathering facts mean?
This checks the servers current config and settings
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.
…
ansbile-playbook ask-become-pass this.yml
Create a list of services to install. Can you do the same with their services?
You can’t make a list for the services.
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
>
- multilines that follow your indentation
Check that your playbook doesn’t have any mistakes
Perform a dry run on your playbook
ansible-playbook –syntax-check this.yml
ansible-playbook -C this.yml
or
ansible-playbook –check this.yml
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
ansible ansible1 -a ‘cat /tmp/multiline.txt’
Why would you use multiple plays
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
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
…
3yy - copy three lines
p - paste
The ansible-playbook command allows you to increase verbosity. What are the levels of verbosity and what do they mean?
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
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
…
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?
…
FACTS - automatically set variables.
What are the three types of variables
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
Show all Ansible facts
What does the argument for your module do in this case?
var prints variables. This is one of the few instances that you don’t have to put the var in curly brackets and quotes
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"ansible_facts[‘default_ipv4’][‘address’]
or
ansible_facts.default_ipv4.address
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
ansible-config view
ansible-config dump –only-changed
ansible-galaxy collection list
ansible-galaxy collection install this.collection