Enrico Zini: Reimagining Ansible variables
This is part of a series of posts on ideas for an ansible-like provisioning
system, implemented in Transilience.
While experimenting with Transilience, I've been giving some thought about
Ansible variables.
My gripes
I like the possibility to define host and group variables, and I like to have a
set of variables that are autodiscovered on the target systems.
I do not like to have everything all blended in a big bucket of global
variables.
Let's try some more prototyping.
My fiddlings
First,
Using
I can also model results from fact gathering into dataclass members:
I like that this way, one can explicitly declare what variables a
One can also fill in variables when instantiating Roles, making parameterized
generic Roles possible and easy:
Outcomes
I like where this is going: having well defined variables for facts and roles,
means that the variables that get into play can be explicitly defined, well
known, and documented.
I think this design lends itself quite well to role reuse:
Role classes could become dataclasses, too, and declare the variables and
facts that they intend to use (typed, even!):
class Role(role.Role): """ Postfix mail server configuration """ # Postmaster username postmaster: str = None # Public name of the mail server myhostname: str = None # Email aliases defined on this mail server aliases: Dict[str, str] = field(default_factory=dict)
dataclasses.asdict()
I immediately gain context variables for rendering Jinja2 templates:
class Role: # [...] def render_file(self, path: str, **kwargs): """ Render a Jinja2 template from a file, using as context all Role fields, plus the given kwargs. """ ctx = asdict(self) ctx.update(kwargs) return self.template_engine.render_file(path, ctx) def render_string(self, template: str, **kwargs): """ Render a Jinja2 template from a string, using as context all Role fields, plus the given kwargs. """ ctx = asdict(self) ctx.update(kwargs) return self.template_engine.render_string(template, ctx)
# From ansible/module_utils/facts/system/platform.py @dataclass class Platform(Facts): """ Facts from the platform module """ ansible_system: Optional[str] = None ansible_kernel: Optional[str] = None ansible_kernel: Optional[str] = None ansible_kernel_version: Optional[str] = None ansible_machine: Optional[str] = None # [...] ansible_userspace_architecture: Optional[str] = None ansible_machine_id: Optional[str] = None def summary(self): return "gather platform facts" def run(self, system: transilience.system.System): super().run(system) # ... collect facts
Facts
action will collect, and what variables a Role needs.
At this point, I can add machinery to allow a Role to declare what Facts it
needs, and automatically have the fields from the Facts class added to the
Role class. Then, when facts are gathered, I can make sure that their fields
get copied over to the Role classes that use them.
In a way, variables become role-scoped, and Facts subclasses can be used like
some kind of Role mixin, that contributes only field members:
# Postfix mail server configuration @role.with_facts([actions.facts.Platform]) class Role(role.Role): # Postmaster username postmaster: str = None # Public name of the mail server myhostname: str = None # Email aliases defined on this mail server aliases: Dict[str, str] = field(default_factory=dict) # All fields from actions.facts.Platform are inherited here! def have_facts(self, facts): # self.ansible_domain comes from actions.facts.Platform self.add(builtin.command( argv=["certbot", "certonly", "-d", f"mail. self.ansible_domain ", "-n", "--apache"], creates=f"/etc/letsencrypt/live/mail. self.ansible_domain /fullchain.pem" ), name="obtain mail.* certificate") # the template context will have the Role variables, plus the variables # of all the Facts the Role uses with self.notify(ReloadPostfix): self.add(builtin.copy( dest="/etc/postfix/main.cf", content=self.render_file("roles/mailserver/templates/main.cf"), ), name="configure /etc/postfix/main.cf")
runner.add_role( "mailserver", postmaster="enrico", myhostname="mail.enricozini.org", aliases= "me": "enrico", , )
- Roles can use variables without risking interfering with each other.
- Variables from facts can have well defined meanings across roles.
- Roles are classes, and can easily be made inheritable.
The Python programming language is one of the most popular and in huge demand. It is free, has a large community, is intended for the development of projects of varying complexity, is easy to learn, and opens up great opportunities for programmers. To work comfortably with it, you need special Python tools, which are able to simplify your work. We have selected the best Python tools that will be relevant in 2021.
Having build a single node Kubernetes cluster and had a poke at what it s doing in terms of networking the next thing I want to do is figure out what it s doing in terms of containers. You might argue this should have come before networking, but to me the networking piece is more non-standard than the container piece, so I wanted to understand that first.
Let s start with a process listing on the host.
Ten years ago
The pandemic was a bit of a mess for most FLOSS conferences. The two
conferences that I help organize -- 



.
On the global stage, about a decade ago, Stephen J. Dubner and Steven Levitt argued in their book 


Pappu Yadav, President Jan Adhikar Party, Bihar May 11, 2021




I have uploaded most of my Machine Learning lecture to YouTube.
The slides are in English, but the audio is in German.
Some very basic contents (e.g., a demo of standard k-means clustering) were left out from this advanced class,
and instead only a link to recordings from an earlier class were given. In this class, I wanted to focus
on the improved (accelerated) algorithms instead. These are not included here (yet).
I believe there are some contents covered in this class you will find nowhere else (yet).
The first unit is pretty long (I did not split it further yet). The later units are shorter recordings.
ML F1: Principles in Machine Learning
Every year since 2005 there is a very good, big and interesting Latin
American gathering of free-software-minded people. Of course, Latin
America is a big, big, big place, and it s not like we are the most
economically buoyant region to meet in something equiparable to
FOSDEM.
What we have is a distributed free software conference originally,
a distributed Linux install-fest (which I never liked, I am against
install-fests), but gradually it morphed into a proper conference:
Festival Latinoamericano de Instalaci n de Software Libre (Latin
American Free Software Installation Festival)
This FLISOL was hosted by the always great and always interesting
Note: This is the continuation of
Too much has been written, a war of support letters is going on, Debian is heading head first like Lemmings into the same war. And then, there is this by the first female President of the American Civil Liberties Union (ACLU):