devops: how to be an ansible contributor · devops: how to be an ansible contributor step – by...

Post on 27-Jun-2020

41 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

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

Developer Advocate, Cisco DevNet – developer.cisco.com

@johnamcdonough

John McDonough

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

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

What Do I Know About Ansible?

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

Read Some Docs

Read Some Docs

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

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!

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!

Fork Ansible on Github

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.

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

Setup Your Development Environment

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

Setup Your Development Environment

Setup Your Development Environment

Setup Your Development Environment

Setup Your Development Environment

Setup Your Development Environment

Read Some Docs … again

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

Read Some Docs … again

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

Create an Ansible Module

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)

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

Read Some Docs … again

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

Read Some Docs … again and again

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

Read Some Docs … again and again

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

Submit a Pull Request

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

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

Read Some Docs … again

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

Submit a Pull Request

Submit a Pull Request

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

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

Submit a Pull Request

• Your Code Passes Tests

• Your Code is marked shipit

• Your Code is Merged

• Wait you're not done yet!

Sync Your Fork

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/

Delete Your Branch

• git branch -d branch1 <--- locally

• git push origin :branch1 <--- remote

• Do it all over again for your next module

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

Got Questions? This is where I'm at!

jomcdono@cisco.com @johnamcdonough http://github.com/movinalot @CiscoDevNet facebook.com/ciscodevnet http://github.com/CiscoDevNet

Thank you!

top related