42
DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough John McDonough

DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

  • Upload
    others

  • View
    24

  • Download
    0

Embed Size (px)

Citation preview

Page 1: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

DevOps: How to Be an Ansible Contributor Step – by – Step

Developer Advocate, Cisco DevNet – developer.cisco.com

@johnamcdonough

John McDonough

Page 2: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

John McDonough Developer Advocate, Cisco

John Works for Cisco DevNet

John Writes Code

John Talks about Code

John Talks about Writing Code

John Writes OK Code and Talks Pretty Good Well

John Contributes to Ansible

Page 3: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

How to be an Ansible Contributor

• What Do I Know About Ansible? • Read Some Docs • Fork Ansible on Github • Setup Your 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 • Sync Your Fork • Delete Your Branch

Page 4: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

What Do I Know About Ansible?

Page 5: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

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

Page 6: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

Read Some Docs

Page 7: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

Read Some Docs

http://docs.ansible.com/ansible/devel/dev_guide/developing_modules_general.html

Page 8: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

Read Some Docs

http://docs.ansible.com/ansible/devel/dev_guide/developing_modules_general.html

Someone wrote these Docs for you! Don't make them Ugly Cry!

Page 9: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

Read Some Docs

http://docs.ansible.com/ansible/devel/dev_guide/developing_modules_general.html

Someone wrote these Docs for you! Don't make them Ugly Cry!

Page 10: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

Fork Ansible on Github

Page 11: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

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.

Page 12: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

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 Fork Their Code

Page 13: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

Setup Your Development Environment

Page 14: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

Setup Your Development Environment

• Clone YOUR Forked Code NOT the Ansible Code! • Setup a Python Virtual Environment in the ansible

Directory – cd ansible

– python3 -m venv venv

• Activate the Virtual Environment – . venv/bin/activate

• Install the Development Requirements – pip install -r requirements.txt

• Run the Development Environment Setup Script – . hacking/env-setup

Page 15: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

Setup Your Development Environment

Page 16: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

Setup Your Development Environment

Page 17: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

Setup Your Development Environment

Page 18: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

Setup Your Development Environment

Page 19: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

Setup Your Development Environment

Page 20: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

Read Some Docs … again

http://docs.ansible.com/ansible/devel/dev_guide/developing_modules_general.html

Page 21: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

Read Some Docs … again

http://docs.ansible.com/ansible/devel/dev_guide/developing_modules_general.html

Page 22: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

Create an Ansible Module

Page 23: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

Create an Ansible Module

• Modules should be concise – "Do One Thing Well"

• 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 (Create / Read / Update / Delete)

Page 24: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

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 Sanity Tests

• Create Unit Tests

Page 25: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

Read Some Docs … again

http://docs.ansible.com/ansible/devel/dev_guide/developing_modules_general.html

Page 26: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

Read Some Docs … again and again

http://docs.ansible.com/ansible/devel/dev_guide/developing_modules_general.html

Page 27: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

Read Some Docs … again and again

http://docs.ansible.com/ansible/devel/dev_guide/developing_modules_general.html

Page 28: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

Submit a Pull Request

Page 29: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

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 Sanity Tests • Create Unit Tests • Commit and Push YOUR Code to YOUR feature branch

Page 30: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

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

Page 31: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

Read Some Docs … again

http://docs.ansible.com/ansible/devel/dev_guide/testing/sanity/index.html

Page 32: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

Submit a Pull Request

Page 33: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

Submit a Pull Request

Page 34: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

Submit a Pull Request – After the Click

• Automated testing happens

• Your code will probably fail – Fix it – Commit it – Push it

• Automated Testing Happens – You do not need to submit a new Pull Request

Page 35: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

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

• Automated Testing Happens – You do not need to submit a new Pull Request

Page 36: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

Submit a Pull Request

• Your Code Passes Tests

• Your Code is marked shipit

• Your Code is Merged

• Wait you're not done yet!

Page 37: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

Sync Your Fork

Page 38: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

Sync Your 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/

Page 39: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

Delete Your Branch

• git branch -d branch1 <--- locally

• git push origin :branch1 <--- remote

• Do it all over again for your next module

Page 40: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

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

Page 41: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

Got Questions? This is where I'm at!

[email protected] @johnamcdonough http://github.com/movinalot @CiscoDevNet facebook.com/ciscodevnet http://github.com/CiscoDevNet

Page 42: DevOps: How to Be an Ansible Contributor · DevOps: How to Be an Ansible Contributor Step – by – Step Developer Advocate, Cisco DevNet – developer.cisco.com @johnamcdonough

Thank you!