how to be an ansible contributor atl slide decks/how-to-… · my automation story 1. how did you...

44
How to be an Ansible Contributor Step-by-Step John McDonough Cisco DevNet – Developer Advocate

Upload: others

Post on 05-Aug-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

How to be an Ansible ContributorStep-by-StepJohn McDonoughCisco DevNet – Developer Advocate

Page 2: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

My automation story

1. How did you get started with Ansible?I signed up to teach a workshop for Cisco UCS and Ansible so I had to learn it.

2. How long have you been using it?Almost Three years

3. What's your favorite thing to do when you Ansible?Eat a sandwich and provision a server.

Page 3: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

John McDonoughCisco DevNet - Developer Advocate

John Works for Cisco DevNetJohn Writes CodeJohn Talks about CodeJohn Talks about Writing CodeJohn Writes OK Code and Talks Pretty Good WellJohn Contributes to Ansible

Page 4: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and 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

Page 5: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

What Do I Know About Ansible?

Page 6: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and 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

Page 7: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

Read Some Docs

https://docs.ansible.com/ansible/latest/dev_guide/developing_modules_general.html

Page 8: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

Read Some Docs

https://docs.ansible.com/ansible/latest/dev_guide/developing_modules_general.html

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

Page 9: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

Read Some Docs

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

https://docs.ansible.com/ansible/latest/dev_guide/developing_modules_general.html

Page 10: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

Fork Ansible on Github

Page 11: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

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– Awareness of 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: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

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– Awareness of 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

Page 13: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

Setup Your DevelopmentEnvironment

Page 14: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

Setup Your Development Environment

• Clone YOUR Forked Code NOT the Ansible Code!– $ git clone https://github.com/johnamcdonough/ansible.git

• Setup a Python Virtual Environment in the ansible Directory– $ cd ansible– Python 3 $ python3 -m venv venv – Python 2 $ virtualenv venv

• Requires virtualenv $ pip install virtualenv

• 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: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

Setup Your Development Environment

Page 16: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

Setup Your Development Environment

Page 17: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

Setup Your Development Environment

Page 18: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

Setup Your Development Environment

Page 19: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

Setup Your Development Environment

Page 20: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

Read Some Docs … again

https://docs.ansible.com/ansible/devel/dev_guide/developing_modules_general.html#common-environment-setup

Page 21: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

Read Some Docs … again

https://docs.ansible.com/ansible/devel/dev_guide/developing_modules_general.html#common-environment-setup

Page 22: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

Create an Ansible Module

Page 23: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

Create an Ansible Module

• Be concise – "Do One Thing Well"• A user does not need to know all the options• Encompass much of the logic for a resource• Think CRUD (Create / Read / Update / Delete)

– Or DRUC, CURD, URCD, DURC, RUCD, etc.– Whatever seems to work best!

Page 24: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

Create an Ansible Module

• 'cd' to the desired directory or create a new directory• Create a new file• Use the "New module development" Template• Test the Module

– Locally – JSON formatted ANSIBLE_MODULE_ARGS file– Playbook – YAML formatted playbook

• Run Sanity Tests• Create/Run Unit Tests

Page 25: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

Read Some Docs … again

https://docs.ansible.com/ansible/latest/dev_guide/developing_modules_general.html#starting-a-new-module

Page 26: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

Read Some Docs … again and again

https://docs.ansible.com/ansible/latest/dev_guide/developing_modules_general.html#contributing-back-to-ansible

Page 27: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

Read Some Docs … again and again

https://docs.ansible.com/ansible/latest/dev_guide/developing_modules_general.html#contributing-back-to-ansible

Page 28: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

Submit a Pull Request

Page 29: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

Create an Ansible Module – Revised

• Create feature branch • 'cd' to the desired directory or create a new directory• 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• Create Pull Request

Page 30: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

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: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

Read Some Docs … again

https://docs.ansible.com/ansible/latest/dev_guide/testing/sanity/index.html

Page 32: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

Submit a Pull Request

Page 33: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

Submit a Pull Request

Page 34: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

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: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

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: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

Submit a Pull Request

• Your Code Passes Tests!• Your Code is marked shipit!• Your Code is Merged!

Page 37: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

Submit a Pull Request

• Your Code Passes Tests!• Your Code is marked shipit!• Your Code is Merged!

• Wait you're not done yet!

Page 38: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

Sync Your Fork

Page 39: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

Sync Your Forkgit remote add upstream https://github.com/ansible/ansible.gitgit remote –v 🡨 what are your remotesOnly need to add the upstream once

git fetch upstream 🡨 fetch the current ansible/develgit checkout devel 🡨 checkout YOUR develgit merge upstream/devel 🡨 merge ansible/devel to YOUR develgit push origin devel 🡨 push YOUR devel to YOUR Ansible fork

https://help.github.com/articles/syncing-a-fork/

Page 40: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

Delete Your Branch

• git branch -d branch1 <--- locally• git push origin :branch1 <--- remote

• Do it all over again for your next module

Page 41: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

Links

• Red Hat– How to Make Your Mark: Ansible Community Contributions -

https://www.ansible.com/resources/webinars-training/how-to-make-ansible-community-contributions– 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 42: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

Got Questions? This is where I'm at!

[email protected]

@johnamcdonough

http://github.com/movinalot

@CiscoDevNet

facebook.com/ciscodevnet

http://github.com/CiscoDevNet

Page 43: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible

https://developer.cisco.com/join/ansiblefest20

Page 44: How to be an Ansible Contributor ATL Slide Decks/How-to-… · My automation story 1. How did you get started with Ansible? I signed up to teach a workshop for Cisco UCS and Ansible