Python

This is very bare-bones documentation on how to use the autogenerated Python classes from the 'pycklets' Library to execute frecklets programatically.

Preparation

First, we need a virtualenv for our project. Assuming we use pyenv, we'd do something like:

pyenv virtualenv 3.7.3 pycklets_example
mkdir pycklets_example
cd pycklets_example
pyenv activate pycklets_example
# if we only want to use the 'freck' script and freckles binary
pip install --pre --extra-index-url https://pkgs.frkl.io/frkl/dev pycklets
# or, if we want to use the freckles Python library directly
pip install --pre --extra-index-url https://pkgs.frkl.io/frkl/dev pycklets[freckles]

Code

Now, create a Python script 'pycklets_run.py', which contains:

from pycklets import Ec2InstanceExists, WordpressStandalone
from pyckles import create_pyckles_context

ec2 = Ec2InstanceExists()
ec2.instance_name = "wordpress_server"
ec2.aws_access_key = "<your aws access key>"
ec2.aws_secret_key = "<your aws secret key>"
ec2.key_name = "yubi"               # ssh-key-pair name
ec2.region = "eu-west-1"
ec2.register_var = "wp_box"
ec2.image_id = "ami-440d4837"          # Debian stretch
ec2.security_groups = ["web-traffic"]  # already exists

# create the instance
run_context = create_pyckles_context(pyckles_packages="pycklets", debug=True)
ec2_details = run_context.run_pycklets(ec2)

ec2_ip = ec2_details["wp_box"]["public_ip_address"]

wps = WordpressStandalone()
wps.wp_title = "My wordpress site"
wps.webserver = "nginx"
wps.hostname = ec2_ip
wps.wp_admin_email = "[email protected]"
wps.wp_admin_password = "password123"
wps.wp_db_password = "wordpress_db_pw"

# install Wordpress
# this Debian image has a default user called 'admin'
run_context.run_pycklets(wps, run_config="admin@{}".format(ec2_ip))

print("Finished. Visit: http://{}".format(ec2_ip))

Now, all we have to do is execute our script:

$ python pycklets_run.py

╭╼ starting run
│  ├╼ preparing adapter: nsbl
│  │  ├╼ preparing execution environment
│  │  │  ├╼ installing python package(s): boto, boto3, botocore
│  │  │  │  ╰╼ ok
│  │  │  ╰╼ ok
│  │  ╰╼ ok
│  ├╼ running frecklet: 538a9336-a9ac-4f53-a7c2-e2de47767c87 (on: localhost)
│  │  ├╼ starting Ansible run
...
...
...

As this is