Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [ansible@control lesson16]$ history
- 1 sudo -i
- 2 sudo yum install -y ansible
- 3 sudo yum install -y epel-release
- 4 yum install -y ansible
- 5 sudo yum install -y ansible
- 6 sudo -i
- 7 ssh-keygen
- 8 ssh-copy-id ansible1
- 9 ssh-copy-id ansible2
- 10 ssh ansible2
- 11 ansible --version
- 12 git clone https://github.com/sandervanvugt/rhce8-live
- 13 git clone https://github.com/sandervanvugt/rhce8-book
- 14 cd rhce8-live/
- 15 ls
- 16 ./countdown 12
- 17 sudo vim /etc/ansible/hosts
- 18 vim myinventory
- 19 ansible -i myinventory all --list-hosts
- 20 ansible -i myinventory dbase --list-hosts
- 21 ansible -i myinventory ungrouped --list-hosts
- 22 cd lesson2/
- 23 ls
- 24 sudo vim /etc/ansible/ansible.cfg
- 25 vim ansible.cfg
- 26 ansible --version
- 27 vim ansible.cfg
- 28 ansible all -m user -a "name=lisa"
- 29 cd ..
- 30 ansible all -m user -a "name=lisa"
- 31 ls
- 32 cd -
- 33 ansible all -m command -a "id lisa"
- 34 cat inventory
- 35 ansible --help
- 36 ../countdown 12
- 37 history
- 38 ansible-doc -l
- 39 ansible-doc -l | wc
- 40 ansible-doc -l | grep vmware
- 41 ansible-doc -l | grep mel
- 42 ansible-doc -l | grep cisco
- 43 ansible-doc -l | grep ios
- 44 ansible-doc user
- 45 ansible all -m ping
- 46 ansible all -m service -a "name=httpd state=started"
- 47 ansible all -m service -a "name=sshd state=started"
- 48 ansible all -m service -a "name=sshd state=stopped"
- 49 history
- 50 ansible all -m ping
- 51 ansible all -m command "id ansible"
- 52 ansible all -m command -a "id ansible"
- 53 ansible-doc service
- 54 ansible all -a "ps aux |grep ssh"
- 55 ansible all -a "ps -aux |grep ssh"
- 56 ansible all -m shell -a "ps -aux |grep ssh"
- 57 ansible all -m command -a "rpm -qa | grep vi"
- 58 ansible all -m shell -a "rpm -qa | grep vi"
- 59 ansible-doc -l cisco
- 60 ansible all -m copy -a 'content="hello world" dest=/etc/motd"
- 61 ansible all -m copy -a 'content="hello world" dest=/etc/motd'
- 62 ansible all -m shell -a "cat /etc/motd"
- 63 history
- 64 vim myscript.sh
- 65 chmod +x myscript.sh
- 66 ./myscript.sh
- 67 vim myscript.sh
- 68 vim ~/.vimrc
- 69 cd ../lesson4/
- 70 ls
- 71 vim vsftpd.yml
- 72 ansible-playbook vsftpd.yml
- 73 cat /etc/hosts
- 74 cat ~/.vimrc
- 75 ../countdown 12
- 76 cat ~/.vimrc
- 77 vim vsftpd.yml
- 78 ls
- 79 vim install-httpd.yml
- 80 ansible-playbook install-httpd.yml
- 81 vim uninstall-httpd.yml
- 82 vim install-httpd.yml
- 83 ansible-doc service
- 84 ansible-doc yum
- 85 vim vsftpd.yml
- 86 ansible-playbook vsftpd.yml
- 87 ansible-playbook --syntax-check vsftpd.yml
- 88 ansible-playbook -C vsftpd.yml
- 89 ansible-playbook -v vsftpd.yml
- 90 vim vsftpd.yml
- 91 ansible-playbook -v vsftpd.yml
- 92 ansible-playbook -vv vsftpd.yml
- 93 ansible-playbook -vvvv vsftpd.yml
- 94 ansible-playbook -vvvvv vsftpd.yml
- 95 ansible-playbook -vvvvvv vsftpd.yml
- 96 ansible-playbook --help | less
- 97 vim web-setup-and-test.yml
- 98 ansible-playbook web-setup-and-test.yml
- 99 ls
- 100 vim install-httpd.yml
- 101 vim web-setup-and-test.yml
- 102 vim install-httpd.yml
- 103 cd ../lesson5/
- 104 ls
- 105 ansible ansible1.example.com -m setup > facts.txt
- 106 less facts.txt
- 107 ls
- 108 vim user.yml
- 109 ansible-playbook user.yml
- 110 ansible-playbook user.yml -e user=linda
- 111 history
- 112 exit
- 113 vim homework1.txt
- 114 pwd
- 115 ls
- 116 cd rhce8-live/
- 117 ls
- 118 cd lesson5/
- 119 vim new-http.yaml
- 120 vim new-unhttp.yaml
- 121 sudo vim /etc/hosts
- 122 ping ansible3.example.com
- 123 vim inventory
- 124 ansible -u root -i inventory ansible3.example.com --ask-pass -m raw -a "yum install python3"
- 125 ansible -u root -i inventory ansible3.example.com --ask-pass -m raw -a "yum install -y python3"
- 126 vim ansible.cfg
- 127 vim new-http.yaml
- 128 ansible-playbook new-http.yaml
- 129 curl http://ansible2.example.com
- 130 vim new-unhttp.yaml
- 131 ansible-playbook new-unhttp.yaml
- 132 history
- 133 sudo firewall-cmd --list-all
- 134 sudo firewall-cmd --add-service ftp
- 135 sudo firewall-cmd --list-all
- 136 sudo firewall-cmd --reload
- 137 sudo firewall-cmd --list-all
- 138 sudo firewall-cmd --add-service ftp --permanent
- 139 sudo firewall-cmd --list-all
- 140 sudo firewall-cmd --add-service ftp
- 141 vim new-http.yaml
- 142 ansible-doc firewalld
- 143 history
- 144 vim new-http.yaml
- 145 vim user.yml
- 146 ansible-playbook user.yml -e user=anna
- 147 ls
- 148 cd
- 149 history | grep git
- 150 cd rhce8-book/
- 151 ls
- 152 less listing66.yaml
- 153 vim listing66.yaml
- 154 cat inventory
- 155 ansible-playbook listing66.yaml
- 156 cd ../rhce8-live/lesson5/
- 157 ls
- 158 cat ../../rhce8-book/listing66.yaml
- 159 less facts.txt
- 160 ls
- 161 cd webservers/
- 162 ls
- 163 vim site.yml
- 164 vim group_vars/lamp
- 165 vim site.yml
- 166 ansible-playbook site.yml
- 167 cat ../../rhce8-book/listing66.yaml
- 168 cat ../../../rhce8-book/listing66.yaml
- 169 cd ..
- 170 vim user.yml
- 171 ansible-vault --help
- 172 ../countdown 12
- 173 cd ../lesson7/
- 174 ls
- 175 cd vault/
- 176 ls
- 177 cat secret.yml
- 178 rm secret.yml
- 179 ansible-vault create secret.yml
- 180 vim create-user.yml
- 181 ansible-playbook create-user.yml
- 182 ansible-playbook --ask-vault-pass create-user.yml
- 183 echo password > vault-pass
- 184 cat vault-pass
- 185 ls -l vault-pass
- 186 chmod 400 vault-pass
- 187 ansible-playbook --vault-password-file=vault-pass create-users.yml
- 188 ansible-playbook --vault-password-file=vault-pass create-user.yml
- 189 ansible-playbook -m setup all
- 190 ansible all -m setup
- 191 pwd
- 192 cd ../../..
- 193 cd rhce8-book/
- 194 vim listing61.yaml
- 195 vim listing62.yaml
- 196 ansible-playbook listing62.yaml
- 197 vim listing63.yaml
- 198 vim listing64.yaml
- 199 vim listing65.yaml
- 200 ansible-playbook listing65.yaml
- 201 ansible-playbook listing66.yaml
- 202 vim listing66.yaml
- 203 vim listing67.yaml
- 204 vim listing68.yaml
- 205 vim listing69.yaml
- 206 vim listing68.yaml
- 207 vim listing69.yaml
- 208 ansible-playbook listing69.yaml
- 209 ansible all -m setup -a "filter=ansible_local"
- 210 cd ../rhce8-live/lesson7/
- 211 ls
- 212 cd facts
- 213 ls
- 214 cat newlocalfacts.yml
- 215 cat localfacts.fact
- 216 ansible-playbook newlocalfacts.yml
- 217 ansible ansible1.example.com -m setup -a "filter=ansible_local"
- 218 pwd
- 219 cd ../lesson5
- 220 cd ..
- 221 cd ../lesson5
- 222 ls
- 223 cd -
- 224 ls
- 225 cd arrays/
- 226 ls
- 227 ls vars/users-dictionary
- 228 cat vars/users-dictionary
- 229 cat vars/users-list
- 230 ls
- 231 vim multi-list.yml
- 232 ansible-playbook multi-list.yml
- 233 vim multi-dictionary.yml
- 234 ansible-playbook multi-dictionary.yml
- 235 ls
- 236 pwd
- 237 ../../countdown 14
- 238 cd ../..
- 239 ls
- 240 cd lesson8
- 241 ls
- 242 vim loopservices.yml
- 243 ansible-playbook loopservices.yml
- 244 vim loopusers.yml
- 245 ansible-playbook loopusers.yml
- 246 vim loop-over-variable.yml
- 247 vim loopvars.yml
- 248 vim loop-over-variable.yml
- 249 ansible-playbook loop-over-variable.yml
- 250 ls
- 251 vim register_command.yml
- 252 pwd
- 253 vim ../../rhce8-book/listing618.yaml
- 254 ansible-playbook ../../rhce8-book/listing618.yaml
- 255 vim register_loop.yml
- 256 ansible-playbook register_loop.yml
- 257 vim register_command.yml
- 258 ansible-playbook register_command.yml
- 259 vim register_command.yml
- 260 ansible-playbook register_command.yml
- 261 vim register_command.yml
- 262 ansible-playbook register_command.yml
- 263 vim register_command.yml
- 264 ansible-playbook register_command.yml
- 265 ansible-doc debug
- 266 history
- 267 vim distro.yml
- 268 ansible-playbook distro.yml
- 269 vim distro.yml
- 270 ansible-playbook distro.yml
- 271 vim quicktest.yml
- 272 ansible-playbook quicktest.yml
- 273 date
- 274 vim quicktest.yml
- 275 ansible-playbook quicktest.yml
- 276 vim quicktest.yml
- 277 ansible-playbook quicktest.yml
- 278 vim quicktest.yml
- 279 vim command-output-test.yml
- 280 ansible-playbook command-output-test.yml
- 281 vim command-output-test.yml
- 282 ../countdown 12
- 283 vim when_multiple
- 284 vim when_multiple.yml
- 285 ansible-playbook when_multiple.yml
- 286 vim when_multiple.yml
- 287 ansible-playbook when_multiple.yml
- 288 vim when_multiple.yml
- 289 ansible-playbook when_multiple.yml
- 290 vim when_multiple.yml
- 291 ansible-playbook when_multiple.yml
- 292 vim when_multiple_complex.yml
- 293 ansible-playbook when_multiple_complex.yml
- 294 vim restart.yml
- 295 ansible-playbook restart.yml
- 296 vim restart.yml
- 297 vim ../../rhce8-book/listing79.yaml
- 298 ansible-playbook ../../rhce8-book/listing79.yaml
- 299 ansible-playbook ../../rhce8-book/listing710.yaml
- 300 vim ../../rhce8-book/listing710.yaml
- 301 vim ../../rhce8-book/listing711.yaml
- 302 vim ../../rhce8-book/listing712.yaml
- 303 vim ../../rhce8-book/listing78.yaml
- 304 ansible-playbook ../../rhce8-book/listing78.yaml
- 305 vim ../../rhce8-book/listing78.yaml
- 306 history
- 307 vim handlers.yml
- 308 ansible-playbook handlers.yml
- 309 touch /tmp/index.html
- 310 ansible-playbook handlers.yml
- 311 vim handlers.yml
- 312 ansible-playbook handlers.yml
- 313 ansible all -m file "name=/var/www/html/index.html state=absent"
- 314 ansible all -m file -a "name=/var/www/html/index.html state=absent"
- 315 ansible-playbook handlers.yml
- 316 history
- 317 vim blocks.yml
- 318 ansible-playbook blocks.yml
- 319 ansible-playbook blocks2.yml
- 320 vim blocks2.yml
- 321 ansible-playbook blocks2.yml
- 322 vim blocks2.yml
- 323 history
- 324 cd rhce8-live/
- 325 cd lesson8/
- 326 vim homework.yml
- 327 vim homework.txt
- 328 ls
- 329 vim homework.yml
- 330 cat homework.yml
- 331 vim homework.txt
- 332 vim failure.yml
- 333 ansible-playbook failure.yml
- 334 vim failure.yml
- 335 ansible-playbook failure.yml
- 336 vim failure2.yml
- 337 ansible-doc fail
- 338 vim failure2.yml
- 339 ansible-playbook failure2.yml
- 340 vim changed.yml
- 341 ansible-playbook changed.yml
- 342 vim failure2.yml
- 343 cd ../lesson9/
- 344 ls
- 345 vim file.yml
- 346 ansible-playbook file.yml
- 347 vim file.yml
- 348 ls -lZ /tmp/
- 349 vim file.yml
- 350 ansible all -m shell -a "ls -lZ /tmp/re*"
- 351 vim copy.yml
- 352 ansible-playbook copy.yml
- 353 cd /tmp
- 354 ls
- 355 cd ansible1.example.com/
- 356 ls
- 357 cd tmp/
- 358 ls
- 359 cat hosts
- 360 cd -
- 361 cd
- 362 cd rhce8-live/
- 363 cd lesson8/
- 364 ls
- 365 cat homework.yml
- 366 ../countdown 15
- 367 ls -lrt
- 368 vim chad.yml
- 369 cat vars/web_vars
- 370 vim chad.yml
- 371 ansible all -m file -a "name=/var/www/html/index.html state=absent"
- 372 vim chad.yml
- 373 ansible-playbook chad.yml
- 374 cat chad.yml
- 375 cat vars/web_vars
- 376 cd ../lesson9/
- 377 ls
- 378 vim selinux.yml
- 379 ansible-playbook selinux.yml
- 380 vim selinux.yml
- 381 ansible-playbook selinux.yml
- 382 vim selinux.yml
- 383 ansible-doc file
- 384 vim selinux.yml
- 385 vim vsftpd-template.yml
- 386 ls
- 387 cat templates/vsftpd.j2
- 388 ansible-playbook vsftpd-template.yml
- 389 ansible ansible2.example.com -a "cat /etc/vsftpd/vsftpd.conf"
- 390 vim hostsfile.yml
- 391 vim templates/hosts.j2
- 392 ansible-playbook hostsfile.yml
- 393 ansible ansible2.example.com -a "cat /etc/hosts"
- 394 vim hostsfile.yml
- 395 history | grep git
- 396 ls
- 397 cat hostsfile.yml
- 398 cat templates/hosts.j2
- 399 ansible-doc sefcontext
- 400 ansible-doc -l | grep selinux
- 401 ansible-doc -l | grep -A 5 -B 5 sefcontext
- 402 ../countdown 13
- 403 cd ../lesson10
- 404 cd ../lesson11/
- 405 ansible-galaxy install geerlingguy.nginx
- 406 cd ~/.ansible/
- 407 ls
- 408 cd roles/
- 409 s
- 410 ls
- 411 cd geerlingguy.nginx/
- 412 ls
- 413 tree
- 414 sudo yum install tree -y
- 415 tree
- 416 cd tasks/
- 417 ls
- 418 vim main.yml
- 419 vim setup-RedHat.yml
- 420 cd ..
- 421 ls
- 422 cd defaults/
- 423 ls
- 424 vim main.yml
- 425 cd ../handlers/
- 426 ls
- 427 vim main.yml
- 428 cd ../templates/
- 429 ls
- 430 vim nginx.repo.j2
- 431 cd
- 432 cd rhce8-live/
- 433 cd lesson11/
- 434 ls
- 435 vim nginx-role.yml
- 436 ansible-playbook nginx-role.yml
- 437 ansible-galaxy --help
- 438 ansible-galaxy --init
- 439 ansible-galaxy myrole --init
- 440 ansible-galaxy myrole init
- 441 ansible-galaxy role init myrole
- 442 ls
- 443 tree myrole/
- 444 cd roles/
- 445 ls
- 446 ls -l
- 447 date
- 448 history | grep git
- 449 tree motd2
- 450 tree motd
- 451 cd motd
- 452 cat defaults/main.yml
- 453 cat meta/main.yml
- 454 cat README.md
- 455 ls
- 456 cat tasks/main.yml
- 457 cat templates/motd.j2
- 458 pwd
- 459 cd ../..
- 460 vim motd-role.yml
- 461 ansible-playbook motd-role.yml
- 462 ansible ansible2.example.com -a "cat /etc/motd"
- 463 sudo yum install rhel-system-roles -y
- 464 ls /usr/share/ansible/roles/
- 465 rpm -qf /usr/share/ansible/roles/rhel-system-roles.network/
- 466 rpm -ql /usr/share/ansible/roles/rhel-system-roles.network/
- 467 rpm -ql rhel-system-roles
- 468 cd /usr/share/doc/rhel-system-roles/
- 469 ls
- 470 cd network/
- 471 ls
- 472 vim example-eth-simple-auto-playbook.yml
- 473 cd ../timesync/
- 474 ls
- 475 vim example-timesync-playbook.yml
- 476 cp example-timesync-playbook.yml ~/rhce8-live/lesson11/
- 477 cd
- 478 cd rhce8-live/lesson11/
- 479 ls
- 480 mv example-timesync-playbook.yml name-that-they-want-it-to-be.yaml
- 481 vim name-that-they-want-it-to-be.yaml
- 482 grep roles /etc/ansible/ansible.cfg
- 483 ../countdown 13
- 484 ansible all -a "cat /etc/sudoers.d/ansible"
- 485 ansible localhost -m debug -a "msg={{ 'password' | password_hash('sha512','mypassword') }}"
- 486 cd ../lesson16/
- 487 ls
- 488 vim userpw.yml
- 489 pwd
- 490 cd ../../rhce8-book/
- 491 grep register *
- 492 vim exercise133.yaml
- 493 grep stdin listing*
- 494 vim listing1313.yaml
- 495 sudo -i
- 496 vim listing1313.yaml
- 497 ls
- 498 cd ../rhce8-live/
- 499 ls
- 500 cd lesson16/
- 501 ls
- 502 vim users-advanced.yml
- 503 vim exercise134-vars.yaml
- 504 vim users-advanced.yml
- 505 vim exercise134-tasks.yaml
- 506 vim users-advanced.yml
- 507 ansible-playbook users-advanced.yml
- 508 vim users-advanced.yml
- 509 vim users-advanced.yml --tags setupremote
- 510 ansible-playbook users-advanced.yml --tags setupremote
- 511 vim inventory
- 512 ansible-playbook users-advanced.yml --tags setupremote
- 513 ssh sharon@ansible2
- 514 vim users-advanced.yml
- 515 history
- 516 history | grep git
- 517 exit
- 518 cd rhce8-live/lesson12/
- 519 vim dmitriy.yaml
- 520 vim vsftpd.j2
- 521 vim dmitriy.yaml
- 522 vim vsftpd.j2
- 523 ansible-playbook dmitriy.yaml
- 524 vim dmitriy.yaml
- 525 ansible-playbook dmitriy.yaml
- 526 sudo yum provides */semanage
- 527 vim dmitriy.yaml
- 528 vim inventory
- 529 ansible-playbook dmitriy.yaml
- 530 vim vsftpd.j2
- 531 lsftp ansible2.example.com
- 532 lftp ansible2.example.com
- 533 cat vsftpd.j2
- 534 vim dmitriy.yaml
- 535 cat dmitriy.yaml
- 536 ls
- 537 cd ../../rhce8-book/
- 538 grep block *
- 539 vim listing731.yaml
- 540 ansible-doc debug
- 541 vim listing731.yaml
- 542 grep yum * 2>/dev/null
- 543 vim listing814.yaml
- 544 grep supported_distro *
- 545 cd ../rhce8-live/
- 546 grep -R supported_dis *
- 547 vim lesson8/chad.yml
- 548 cd lesson16/
- 549 vim users-advanced.yml
- 550 cd ../lesson13/
- 551 ls
- 552 vim pascal.py
- 553 ./pascal.py --list
- 554 ansible-inventory -i pascal.py --graph
- 555 ansible-playbook --list-tasks ../lesson16/users-advanced.yml
- 556 vim includes.yml
- 557 vim install-and-setup.yml
- 558 ansible-playbook includes.yml
- 559 ansible-playbook --list-tasks includes.yml
- 560 vim imports.yaml
- 561 vim tasks/service.yaml
- 562 vim tasks/firewall.yaml
- 563 ansible-playbook --list-tasks imports
- 564 ansible-playbook --list-tasks imports.yaml
- 565 ansible-playbook imports.yaml
- 566 vim imports.yaml
- 567 ansible-playbook imports.yaml
- 568 vim inventory
- 569 ansible-playbook imports.yaml
- 570 ../countdown 14
- 571 cd ../../rhce8-book/
- 572 vim listing111.yaml
- 573 vim listing112.j2
- 574 ansible-playbook listing111.yaml --check --diff
- 575 vim listing112.j2
- 576 ansible-playbook -vvvv listing111.yaml
- 577 grep log_path /etc/ansible/ansible.cfg
- 578 ansible-playbook --list-tasks exercise81.yaml
- 579 ansible-playbook --start-at-task "add a message" --step exercise81.yaml
- 580 vim listing116.yaml
- 581 ansible-playbook listing116.yaml
- 582 vim listing117.yaml
- 583 vim listing116.yaml
- 584 vim listing119.yaml
- 585 ansible-playbook listing119.yaml
- 586 vim listing119.yaml
- 587 ansible-playbook listing119.yaml
- 588 ansible-doc stat
- 589 vim listing1113.yaml
- 590 ansible-playbook listing1113.yaml
- 591 vim listing1113.yaml
- 592 vim listing1111.yaml
- 593 ansible-playbook listing1111.yaml
- 594 vim listing1115.yaml
- 595 ansible-playbook listing1115.yaml --tags services
- 596 vim listing1115.yaml
- 597 ansible-playbook listing1115.yaml --tags services
- 598 ls
- 599 vim chapters.txt
- 600 ../rhce8-live/countdown 13
- 601 cd /usr/share/doc/rhel-system-roles/
- 602 ls
- 603 cd selinux/
- 604 ls
- 605 vim example-selinux-playbook.yml
- 606 pwd
- 607 cd
- 608 cd rhce8-live/lesson16/
- 609 vim software-advanced.yml
- 610 cd ../../rhce8-book/
- 611 grep yum_repo *
- 612 vim exercise122-server.yaml
- 613 ansible-playbook exercise122-server.yaml
- 614 vim exercise122-client.yaml
- 615 ansible-playbook exercise122-client.yaml
- 616 ansible all -a "yum repolist"
- 617 history
- 618 ../rhce8-live/countdown 13
- 619 ansible-doc | grep stratis
- 620 ansible-doc -l | grep stratis
- 621 sudo yum install -y vdo
- 622 cd ../rhce8-live/
- 623 cd lesson16/
- 624 ls
- 625 vim storage-advanced.yml
- 626 ansible-playbook storage-advanced.yml
- 627 ansible all -m ping
- 628 vim inventory
- 629 sudo vim /etc/hosts
- 630 ssh root@ansible3
- 631 ssh-copy-id ansible3
- 632 ssh ansible3
- 633 ansible all -m ping
- 634 ansible-playbook storage-advanced.yml
- 635 vim inventory
- 636 ansible all -a "dd if=/dev/zero of=/dev/sdb bs=1M count=1"
- 637 ansible-playbook storage-advanced.yml
- 638 ansible all -a "reboot"
- 639 ansible all -m ping
- 640 history
- 641 ansible-playbook storage-advanced.yml
- 642 history
- 15.3 Configuring Storage Advanced Exercise
- At the end of this chapter it's time again for an advanced exercise. This is probably the most advanced exercise of all exercises in this book, so make sure to take your time to understand all that is covered. To work on this exercise, you have need managed machines with an additional disk device: add a 10 GB second disk to host ansible2, and a 5 GB second disk to host ansible3. The exercise assumes the name of the second disk is /dev/sdb, if a different disk name is used in your configuration, change this according to your specifications.
- Exercise 15.3: Setting up an Advanced Storage Solution
- In this exercise you'll need to set up a storage solution that meets the following requirements:
- • Tasks in this playbook should only be executed on hosts where the device /dev/sdb exists.
- • If no device /dev/sdb exists, the playbook should print "device sdb not present" and stop executing tasks on that host
- • Configure the device with one partition that includes all available disk space
- • Create an LVM volume group with the name vgfiles
- • If the volume group is bigger than 5 GB, create an LVM logical volume with the name lvfiles and a size of 6 GB. Note that you must check the LVM Volume Group size and not the /dev/sdb1 size, because in theory you could have multiple block devices in a volume group.
- • If the volume group is equal to or smaller than 5 GB, create an LVM logical volume with the name lvfiles and a size of 3 GB
- • Format the volume with the XFS filesystem
- • Mount it on the /files directory
- 1. As this is going to be a bigger playbook, it's wise to split development into different parts, so that the different parts can be tested individually. If this would be a task on the EX294 exam, it's smart to start with the most challenging task, and write it in a small playbook so that it can run independently. This is because of time management: if you can't configure the challenging task, it doesn't make sense to spend your time on other tasks. With this in mind, let's focus on the condition where you need to check the size of the volume group. It might not be the best idea to start working on all tasks that are required to get you testing the volume group that needs to be created. You can however perfectly write a test that works on a default volume group, and that is what we're going to do first, using the name of the default volume group on CentOS 8, which is "cl". The purpose is to test the constructions, which is why it doesn't really matter that the two tasks have overlapping when statements. So create a file with the name exercise153-dev1.yaml and give it the following contents:
- ---
- - name: get vg sizes
- hosts: all
- tasks:
- - name: find small vgroup sizes
- debug:
- msg: volume group smaller than or equal to 20G
- when:
- - ansible_facts['lvm']['vgs']['cl'] is defined
- - ansible_facts['lvm']['vgs']['cl']['size_g'] <= 20.00
- - name: find large vgroup size
- debug:
- msg: volume group larger than or equal to 19G
- when:
- - ansible_facts['lvm']['vgs']['cl'] is defined
- - ansible_facts['lvm']['vgs']['cl']['size_g'] >= 19.00
- 2. Run the playbook, using ansible-playbook exercise153-dev1.yaml. You'll notice that it fails with the error seen in listing 15.12:
- Listing 15.12: exercise153-dev1.yaml Failure Message
- TASK [find small vgroups sizes] ***************************************************
- fatal: [ansible1]: FAILED! => {"msg": "The conditional check 'ansible_facts['lvm']['vgs']['cl']['size_g'] <= 20.00' failed. The error was: Unexpected templating type error occurred on ({% if ansible_facts['lvm']['vgs']['cl']['size_g'] <= 20.00 %} True {% else %} False {% endif %}): '<=' not supported between instances of 'AnsibleUnsafeText' and 'float'\n\nThe error appears to be in '/home/ansible/rhce8-book/exercise153-dev1.yaml': line 5, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - name: find small vgroups sizes\n ^ here\n"}
- fatal: [ansible2]: FAILED! => {"msg": "The conditional check 'ansible_facts['lvm']['vgs']['cl']['size_g'] <= 20.00' failed. The error was: Unexpected templating type error occurred on ({% if ansible_facts['lvm']['vgs']['cl']['size_g'] <= 20.00 %} True {% else %} False {% endif %}): '<=' not supported between instances of 'AnsibleUnsafeText' and 'float'\n\nThe error appears to be in '/home/ansible/rhce8-book/exercise153-dev1.yaml': line 5, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - name: find small vgroups sizes\n ^ here\n"}
- fatal: [ansible3]: FAILED! => {"msg": "The conditional check 'ansible_facts['lvm']['vgs']['cl']['size_g'] <= 20.00' failed. The error was: Unexpected templating type error occurred on ({% if ansible_facts['lvm']['vgs']['cl']['size_g'] <= 20.00 %} True {% else %} False {% endif %}): '<=' not supported between instances of 'AnsibleUnsafeText' and 'float'\n\nThe error appears to be in '/home/ansible/rhce8-book/exercise153-dev1.yaml': line 5, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - name: find small vgroups sizes\n ^ here\n"}
- fatal: [ansible4]: FAILED! => {"msg": "The conditional check 'ansible_facts['lvm']['vgs']['cl']['size_g'] <= 20.00' failed. The error was: Unexpected templating type error occurred on ({% if ansible_facts['lvm']['vgs']['cl']['size_g'] <= 20.00 %} True {% else %} False {% endif %}): '<=' not supported between instances of 'AnsibleUnsafeText' and 'float'\n\nThe error appears to be in '/home/ansible/rhce8-book/exercise153-dev1.yaml': line 5, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - name: find small vgroups sizes\n ^ here\n"}
- skipping: [ansible5]
- skipping: [ansible6]
- TASK [find large vgroups sizes] ***************************************************
- skipping: [ansible5]
- skipping: [ansible6]
- 3. As you can see in the errors in listing 15.12, there are two problems in the playbook. The first problem is that there is no ignore_errors in the failing play, which means that only hosts that haven't failed will reach the next task. The second error is the "Unexpected templating error". The playbook as it is now tries to perform a logical test to compare the value of two variables that have an incompatible variable type. The Ansible fact has the type "AnsibleUnsafeText", and the value of 20.00 is a float, and not an integer. To make this test work, you'll have to force the type of both variables to be set to an integer. Let's write exercise153-dev2.yaml where this is happening - notice the use of the filter int which is essential for the success of this playboo:
- ---
- - name: get vg sizes
- ignore_errors: yes
- hosts: all
- tasks:
- - name: set vgroup sizes in variables
- set_fact:
- vgsize: "{{ ansible_facts['lvm']['vgs']['cl']['size_g'] | int }}"
- - name: debug this
- debug:
- msg: the value of vgsize is {{ vgsize }}
- - name: testing big vgsize value
- debug:
- msg: the value of vgsize is bigger than 5
- when: vgsize | int > 5
- - name: testing small vgsize value
- debug:
- msg: the value of vgsize is smaller than 5
- when: vgsize | int <= 5
- 4. Run this playbook, you'll notice it is skipping and ignoring some tasks, but doesn't fail anywhere, which means that this playbook although absolutely not perfect is useable as example to test the size of the vgfiles volume group later in this exercise.
- 5. Now that you've tested the most complex part of the assignment, you can start writing the rest of the playbook. As this playbook has quite a few tasks to accomplish, it may be smart to define the rough structure, and ensure that all elements that are needed later are at least documented, so that you can later work out the details. So let's start with the first part, where the play header is defined, as well as the rough structure. This is the part where you still have the global overview of all the tasks in this requirement, so you need to make sure you won't forget about them later - which is a real risk if you've been into details too much for too long.
- ---
- - name: set up hosts that have an sdb device
- hosts: all
- tasks:
- - name: getting out with a nice failure message if there is no second disk
- # fail:
- debug:
- msg: write a nice failure message and a when test here
- # when: something
- - name: create a partition
- #parted
- debug:
- msg: creating the partition
- - name: create a volume group
- #lvg:
- debug:
- msg: creating the volume group
- - name: get the vg size and store it in a variable
- #set_fact:
- debug:
- msg: storing variable as an integer
- - name: create an LVM on big volume groups
- #lvol:
- debug:
- msg: use when statement to create 6g lvol if vsize > 5
- - name: create an LVM on small volume groups
- #lvol:
- debug:
- msg: use when statement to create 3g lvol if vsize <= 5
- - name: formatting the XFS filesystem
- # filesystem
- debug:
- msg: creating the filesystem
- - name: mounting /dev/vgfiles/lvfiles
- # mount:
- debug:
- msg: mounting the volume
- 6. The advantage of a generic structure like the one you've just defined, is that you can run a test at any moment. Now it's time to fill it in. Let's start with the play header and the check if /dev/sdb is present on the managed system:
- ---
- - name: setup up hosts that have an sdb device
- hosts: all
- tasks:
- - name: getting out with a nice failure message if there is no second disk
- fail:
- msg: there is no second disk
- when: ansible_facts['devices']['sdb'] is not defined
- 7. At this point I'd recommend you run a test to see that the playbook really is going to skip all hosts that don't have a second disk device. Use ansible-playbook exercise153.yaml to do so and observe that you see a lot of skipping messages in the output.
- 8. If all is well so far, you can continue to create the partition, and let's do the logical volume group as well. Here are the tasks you need to enter. Notice that no size is specified at any point, which means that the partition as well as the VG will be allowed to grow up to the maximum size:
- - name: create a partition
- parted:
- device: /dev/sdb
- number: 1
- state: present
- - name: create a volume group
- lvg:
- pvs: /dev/sdb1
- vg: vgfiles
- 9. At this point you can insert the part where you are going to save the volume group size into a variable, which can be used in the when statement that is going to occur in one of the next tasks. Also, because it's good to check a lot while you are writing a complex playbook, let's use the debug module to verify the results:
- - name: get vg size and convert to integer in new variable
- set_fact:
- vgsize: "{{ ansible_facts['lvm']['vgs']['vgfiles']['size_g'] | int }}"
- - name: show vgsize value
- debug:
- var: "{{ vgsize }}"
- 10. After this important step, it's time to run a test. If you need it, you can find a sample playbook of the state so far as exercise153-step9.yaml in the GitHub repository at https://github.com/sandervanvugt/rhce8-book, but it's obviously much better and recommended to run your own code! So use ansible-playbook exercise153.yaml to verify what you've got so far. Notice that you must make sure to run it on hosts that don't have any configuration yet, if configuration already exists that will most likely give you false positives! So if you want to make sure all is clean, use ansible all -a "dd if=/dev/zero of=/dev/sdb bs=1M count=10" to wipe the /dev/sdb devices on your managed hosts, followed by ansible all -m reboot to also reboot all of them before you're testing. The purpose of all this is that at this point you see the error message that is in listing 15.13. Before moving on to the next step, try to understand what is going wrong.
- Listing 15.13: Error Message After Exercise 15.3 Step 10
- TASK [get vg size and convert to integer in new variable] ******************************
- fatal: [ansible2]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'vgfiles'\n\nThe error appears to be in '/home/ansible/rhce8-book/exercise153-step9.yaml': line 18, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n vg: vgfiles\n - name: get vg size and convert to integer in new variable\n ^ here\n"}
- fatal: [ansible3]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'vgfiles'\n\nThe error appears to be in '/home/ansible/rhce8-book/exercise153-step9.yaml': line 18, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n vg: vgfiles\n - name: get vg size and convert to integer in new variable\n ^ here\n"}
- 11. As you can see, the variable that you are trying to use, has no value yet. And that is for the simple reason that fact gathering is required to set the variable, and fact gathering is happening at the beginning of the playbook. So at this point, you'll need to add a task that runs the setup module right after creating the volume group, and then you can try again. In the output you'll have to look at the [show vgsize value] task, that should look all right now, and everything after that can be ignored. See exercise153-step11.yaml in the GitHiub repository if you need the complete example.
- ...
- - name: create a volume group
- lvg:
- pvs: /dev/sdb1
- vg: vgfiles
- - name: run the setup module so that we can use updated facts
- setup:
- - name: get vg size and convert to integer in new variable
- set_fact:
- vgsize: "{{ ansible_facts['lvm']['vgs']['vgfiles']['size_g'] | int }}"
- - name: show vgsize value
- debug:
- var: "{{ vgsize }}"
- ...
- 12. Assuming that all went well, you can now add the two conditional tests, where according to the vgsize value the lvol module will be used to create the logical volumes:
- - name: create an LVM on big volume groups
- lvol:
- vg: vgfiles
- lv: lvfiles
- size: 6g
- when: vgsize | int > 5
- - name: create an LVM on small volume groups
- lvol:
- vg: vgfiles
- lv: lvfiles
- size: 3g
- when: vgsize | int <=5
- 13. Next, you can add the tasks to format the volumes with the XFS filesystem, and mount them:
- - name: formatting the XFS filesystem
- filesystem:
- dev: /dev/vgfiles/lvfiles
- fstype: xfs
- - name: mounting /dev/vgfile/lvfiles
- mount:
- path: /file
- state: mounted
- src: /dev/vgfiles/lvfiles
- 14. That's all! The playbook is now ready for use. Run it, using ansible-playbook exercise153.yaml and verify its output.
- 15. Use the ad-hoc command ansible ansible2,ansible3 -a "lvs" to show LVM logical volume sizes on the machines with the additional hard drive. You should see that all has worked out well and you are done!
Add Comment
Please, Sign In to add comment