Learn how and why John McDonough contributes to Ansible and how you can too. We’ll arm you with what you need to know, things like Python, Git, and YAML.
1. How to be an Ansible Contributor
Step – by – Step
Developer Advocate, Cisco
@johnamcdonough
John McDonough
2. John McDonough
Developer Advocate, Cisco
John Works for Cisco DevNet
JohnWrites Code
JohnTalks about Code
JohnTalks about Writing Code
John Writes OK Code andTalks Pretty GoodWell
John Contributes to Ansible
3. How to be an Ansible Contributor
• What Do I Know About Ansible?
• Read Some Docs
• Fork Ansible on Github
• SetupYour Development Environment
• Read Some Docs… again
• Create an Ansible Module
• Read Some Docs… again
• Read Some Docs… again and again!
• Submit a Pull Request
• Read Some Docs… again
• SyncYour Fork
• DeleteYour Branch
5. What Do I know About Ansible?
• Not that Much … but it's Enough!
• I know how to
– Install Ansible
– Create/Run Ansible playbooks
– Run Ansible in very very very verbose mode
– Write Python Code (can be other languages, python is best)
– Use github.com and git
– Google Stuff
11. Fork Ansible (docs say clone – I say fork)
• Forking a Github repository is
– Making a copy of that repository on github under YOUR account
– At that point in time
– Connected to the original but not updated by the original
• https://github.com/ansible/ansible
– Fork is not a git command and is done in the github.com interface
• hub – git from the command line - https://hub.github.com/
• hub is an extension to command-line git do everyday GitHub tasks without ever leaving the
terminal.
12. Fork Ansible (docs say clone – I say fork)
• Forking a Github repository is
– Making a copy of that repository on github under YOUR account
– At that point in time
– Connected to the original but not updated by the original
• https://github.com/ansible/ansible
– Fork is not a git command and is done in the github.com interface
• hub – git from the command line - https://hub.github.com/
• hub is an extension to command-line git do everyday GitHub tasks without ever leaving the
terminal.
Your ForkTheir Code
14. SetupYour Development Environment
• Clone YOUR Forked Code NOT the Ansible Code!
• Setup a PythonVirtual Environment in the ansible
Directory
– cd ansible
– python3 -m venv venv
• Activate theVirtual Environment
– . venv/bin/activate
• Install the Development Requirements
– pip install -r requirements.txt
• Run the Development Environment Setup Script
– . hacking/env-setup
23. Create an Ansible Module
• Modules should be concise – "Do OneThingWell"
• Modules should not require a user to know all the
underlying options
• Modules should encompass much of the logic for
interacting with a resource
• Think CRUD
• I mean CUD (Create / Update / Delete)
24. Create an Ansible Module
• 'cd' to the desired directory
• Create a new file
• Use the "New module development"Template
• Test the Module
– Locally
– Playbook
• Run SanityTests
• Create UnitTests
25. Read Some Docs … again
http://docs.ansible.com/ansible/devel/dev_guide/developing_modules_general.html
26. Read Some Docs … again and again
http://docs.ansible.com/ansible/devel/dev_guide/developing_modules_general.html
27. Read Some Docs … again and again
http://docs.ansible.com/ansible/devel/dev_guide/developing_modules_general.html
29. Create an Ansible Module – Revised
• 'cd' to the desired directory
• Create feature branch
• Create a new file
• Use the "New module development"Template
• Test the Module
– Locally
– Playbook
• Run SanityTests
• Create UnitTests
• Commit and PushYOUR Code toYOUR feature branch
30. Submit a Pull Request
• Pull Requests can only be submitted against one
module
• One feature branch per Pull Request
– git checkout -b <feature branch name> Create
– git branch List branches
31. Read Some Docs … again
http://docs.ansible.com/ansible/devel/dev_guide/testing/sanity/index.html
34. Submit a Pull Request – After the Click
• Automated testing happens
• Your code will probably fail
– Fix it
– Commit it
– Push it
• AutomatedTesting Happens
– You do not need to submit a new Pull Request
35. Submit a Pull Request – Reviewers
• When your code is "Good" it will be merged… maybe.
• There are reviewers and maintainers that need to approve your code
– They will recommend changes
– They will hurt your feelings
– They will break you!
– They will help you be better!
• Make the changes that are requested
– Commit it
– Push it
• AutomatedTesting Happens
– You do not need to submit a new Pull Request
36. Submit a Pull Request
• Your Code PassesTests
• Your Code is marked shipit
• Your Code is Merged
• Wait you're not done yet!
38. SyncYour Fork
git remote add upstream https://github.com/ansible/ansible.git
git remote –v what are your remotes
Only need to add the upstream once
git fetch upstream fetch the current ansible/devel
git checkout devel checkout YOUR devel
git merge upstream/devel merge ansible/devel to YOUR devel
git push origin devel push YOUR devel to YOUR Ansible fork
https://help.github.com/articles/syncing-a-fork/
39. DeleteYour Branch
• git branch -d branch1 <--- locally
• git push origin :branch1 <--- remote
• Do it all over again for your next module
40. Links
• Blog - http://cs.co/sxsw2019
– “How to Contribute” video: https://www.youtube.com/watch?v=VAbnJcyIMYA&feature=youtu.be
• Matt Davis
– Ansible Module Development video - https://github.com/nitzmahone/ansible-modules-101
– Ansible Module Development 101 github - https://www.ansible.com/ansible-module-development-101
• Ansible Links:
– Ansible on Github - https://github.com/ansible/ansible
– Ansible module development: getting started -
https://docs.ansible.com/ansible/devel/dev_guide/developing_modules_general.html
– Testing Ansible - https://docs.ansible.com/ansible/devel/dev_guide/testing.html
• Learning
– DevNet Learning Labs an introduction - https://developer.cisco.com/learning/modules/sdx-ansible-intro
– DevNet Learning Labs a bunch of labs - https://developer.cisco.com/learning/modules?keywords=ansible
41. Got Questions? This is where I'm at!
jomcdono@cisco.com
@johnamcdonough
http://github.com/movinalot
@CiscoDevNet
facebook.com/ciscodevnet
http://github.com/CiscoDevNet