Ansible 101 – Episode 7 – Molecule Testing and Linting and Ansible Galaxy

    4
    25



    Jeff Geerling (geerlingguy) explores Ansible Galaxy, ansible-lint, Molecule, and testing Ansible roles and playbooks based on content in the bestselling Ansible book, Ansible for DevOps.

    There’s a role for that! https://www.ansible.com/theres-a-role-for-that
    Making your playbooks maintainable: https://www.jeffgeerling.com/blog/2019/make-your-ansible-playbooks-flexible-maintainable-and-scalable-ansiblefest-austin-2018

    Buy Ansible for DevOps: https://www.ansiblefordevops.com

    Sponsor Jeff on GitHub: https://github.com/sponsors/geerlingguy
    Support Jeff on Patreon: https://www.patreon.com/geerlingguy

    Contents:

    00:00:00 – Start
    00:00:20 – Intro
    00:05:13 – Questions from last episode
    00:10:35 – Ansible Galaxy requirements files
    00:15:58 – Mac development playbook
    00:17:17 – A new chapter for testing
    00:19:15 – The Ansible testing spectrum
    00:23:50 – Testing inline in playbooks
    00:28:39 – Linting with yamllint
    00:34:40 – Check syntax with –syntax-check
    00:37:30 – Linting with ansible-lint
    00:42:42 – Introduction to Molecule
    00:47:23 – Testing a role with Molecule
    00:55:52 – Role dev with molecule converge
    00:59:15 – Using molecule login
    01:00:54 – Other molecule commands
    01:02:12 – Outtro

    source

    Previous articleGetting started with AWX / Ansible Tower / Automation Controller
    Next articlePassing External Value to Ansible Playbooks | #Ansible #Fullcourse | techbeatly

    25 COMMENTS

    1. Thank you for the great series. I'm going through the book, and using these videos, as well.
      In the "Testing a role with Molecule" part, seems that the `init` command should be different on newer Molecule versions, at least on 3.5.1. You need to specify a driver like `molecule init role myrole –driver-name docker`, otherwise Molecule will use "delegated" driver.

    2. ROFL whilst following your segment about yamllint, this is 6 months after your vid, you might want to practice what you preach 🙂

      OK, the line too long warnings are mostly negligible, but the wrong indentation actually leads to code unintentionally being run in this case unless I am totally wrong, so it is probably an actual bug. When I indented that part to a full tab, it complained there was no end for that block, so who knows how ansible interoperates it.

      ./roles/geerlingguy.homebrew/.travis.yml
      34:81 error line too long (81 > 80 characters) (line-length)
      58:81 error line too long (85 > 80 characters) (line-length)
      63:81 error line too long (104 > 80 characters) (line-length)

      ./roles/geerlingguy.homebrew/tasks/main.yml
      8:81 error line too long (82 > 80 characters) (line-length)
      16:81 error line too long (81 > 80 characters) (line-length)
      88:3 error wrong indentation: expected 4 but found 2 (indentation)
      115:81 error line too long (95 > 80 characters) (line-length)

      ./roles/geerlingguy.homebrew/tests/test.yml
      12:10 error too many spaces inside braces (braces)
      12:80 error too many spaces inside braces (braces)
      12:81 error line too long (81 > 80 characters) (line-length)

    3. TASK [Gathering Facts] *******************************************************
      fatal: [instance]: UNREACHABLE! => {"changed": false, "msg": "Failed to create temporary directory.In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote tmp path in ansible.cfg to a path rooted in "/tmp", for more error information use -vvv. Failed command was: ( umask 77 && mkdir -p "` echo ~/.ansible/tmp `"&& mkdir ~/.ansible/tmp/ansible-tmp-1604936469.4416668-21271-161981161453473 && echo ansible-tmp-1604936469.4416668-21271-161981161453473="` echo ~/.ansible/tmp/ansible-tmp-1604936469.4416668-21271-161981161453473 `" ), exited with result 1", "unreachable": true}

      i get this error when i try to test :/