Jinja2 Cheatsheet

Basic Jinja

Simple substitution of the value of foo

{{ foo }}

Simple conditional

{%if foo } Stuff to include {% endif }

Uninstall a python package + [source,bash] ----

pip uninstall ansible ----

See what versions are available (use illegal version string!)

pip install ansible==foobar

Upgrade a package

pip install --upgrade ansible or pip install ansible -U

Package Management

List installed packages

pip list

List installed packages

pip list --outdated

Upgrade installed package

pip install --upgrade ansible or -U

Capture installed packages

pip freeze > requirements.txt

Install a dependencies file

pip freeze -r requirements.txt

Deleting secondary dependencies, not so easy, hacky solution? :(

  1. Capture your dependencies pip freeze > requirements.ym;

  2. Edit requirements.yml removing unwanted dependencies

  3. Make a new virtualenv

  4. Install your new dependencies list pip install -r requirements.yml

Tony Kay avatar
About Tony Kay
Team lead for Automation and Management in Red Hat's GPTE DevOps and Automation team. Working globally, I focus primarily on Hybrid Cloud Automation with Ansible. About 2/3rds of my time is automating production cloud deployments and developing both code and training content. I also deliver Automation training globally to both Red Hat and Partner Consultants and Architects on cloud infrastructure using Ansible and on OpenShift/Kubernetes.
comments powered by Disqus