Technology Tales

Notes drawn from experiences in consumer and enterprise technology

18:38, 26th July 2022

Working with playbooks for Ansible

Ansible playbooks are human-readable files written in a basic language that record and execute configuration, deployment and orchestration functions, allowing users to define policies for remote systems or outline steps in broader IT processes. They can manage configurations and deployments at a basic level, and at a more advanced level can sequence multi-tier rollouts with rolling updates, delegate actions to other hosts and interact with monitoring servers and load balancers. Key areas covered in working with playbooks include templating via Jinja2, data manipulation using filters, conditional logic, loops, error handling, variable management and the use of roles for reusable content.

18:37, 26th July 2022

Intro to playbooks for Ansible

Ansible Playbooks are a configuration management and multi-machine deployment system that allows users to define repeatable, reusable automation tasks written in YAML format. A playbook consists of one or more ordered plays, each targeting specific managed nodes and executing one or more tasks that call Ansible modules.

Playbooks run sequentially from top to bottom, and most modules operate idempotently, meaning the outcome remains consistent regardless of how many times a playbook is run. Tasks can be executed synchronously or asynchronously, and behaviour can be further controlled through playbook keywords, command-line flags and inventory settings.

The ansible-pull command inverts the standard architecture by having nodes check out configuration instructions from a Git repository rather than receiving them via a central push. Before running playbooks in a live environment, users can verify them using built-in flags such as --check, --diff and --syntax-check, or through external tools such as ansible-lint, which provides detailed feedback on potential errors and rule violations.

18:36, 26th July 2022

Creating a playbook for Ansible

Ansible playbooks are YAML-formatted automation blueprints used to deploy and configure managed nodes, structured around plays, tasks and modules. A play maps an ordered list of tasks to managed nodes in an inventory, while each task references a single module, which is a unit of code that Ansible runs on those nodes.

To create a basic playbook, a YAML file is set up with named plays and tasks, such as pinging hosts and printing a message, then executed via the command line using the ansible-playbook command. When run, Ansible first gathers facts about the inventory by default, then executes each task in order, reporting the status of every operation per host and producing a final recap summarising the results.

A successful run shows an OK status for each task across all hosts, confirming that the defined operations completed without error. It is recommended that descriptive names be given to plays and tasks to make verification and troubleshooting more straightforward.

18:35, 26th July 2022

How to update/upgrade Debian/Ubuntu Linux using Ansible

Keeping Debian and Ubuntu Linux servers up to date is essential for security and stability, particularly when managing multiple machines. Ansible simplifies this process by using its apt module to refresh the package cache and upgrade all installed packages across servers simultaneously, employing apt-get rather than aptitude to handle the updates. Where kernel upgrades are applied, a reboot is often required, and Ansible can check for the presence of the /var/run/reboot-required file to determine whether this is necessary, automatically rebooting any affected server and waiting for it to come back online before continuing. A hosts file is used to define the target servers, and the full logic is written into a playbook that can be executed with a single command, making the entire update and reboot process repeatable and consistent across a Debian-based infrastructure.

18:35, 26th July 2022

ansible.builtin.apt module – Manages apt-packages

The apt module serves as a tool for managing packages on Debian-based systems, enabling actions such as installation, removal and updates. It allows users to specify the desired state of a package, whether present, absent or latest, and includes options for handling dependencies and cache updates. Parameters like update_cache ensure repositories are refreshed before operations, while features such as default_release and allow_downgrade provide control over version selection and conflict resolution.

The module supports installing specific versions of packages, managing build dependencies and performing system upgrades through options like dist, safe or full. Its functionality extends to cleaning caches, removing unused dependencies and purging configuration files when necessary. By integrating these capabilities, the module streamlines package management tasks, offering flexibility for both routine maintenance and targeted installations.

18:33, 21st July 2022

Using cURL in Python with PycURL

PycURL is a Python interface to the libcURL library that enables data transfer to and from servers, supporting multiple protocols including HTTPS, FTPS, SMTP, IMAP and SMB, among others. It is particularly well suited for testing REST APIs, downloading files and handling large numbers of concurrent connections, and is notably faster than the popular Python Requests library.

Installation is straightforward across operating systems, with Mac and Linux requiring no additional dependencies, while Windows users may need to address a few prerequisites beforehand. Once installed, PycURL can be used to perform HTTP GET requests to retrieve data from a given URL, examine response headers, send form data via POST, upload files using either multipart POST or PUT requests, send DELETE requests to remove server-side resources and write responses directly to a local file, all through a relatively consistent coding pattern built around the setopt function and the Curl object.

15:54, 8th July 2022

FOSS4Spectroscopy: R vs Python

Bryan Hanson's FOSS for Spectroscopy project, which catalogues free and open-source software for spectroscopic applications, received a major update in July 2022, at which point Python packages outnumbered R packages by more than two to one. Packages are discovered by searching four repositories, namely CRAN, GitHub, PyPi.org and juliapackages.org, across a range of spectroscopic topics including NMR, Raman, FT-IR, XRF and several others. To support automated searching of GitHub and PyPi.org, Hanson developed a package called webu, which handles API queries and incorporates deliberate delays to avoid overloading servers. Raw search results require considerable manual inspection and cleaning before they are suitable for inclusion in the main database, with additional scripts used to remove duplicate entries and resolve inconsistencies in package naming conventions.

09:02, 1st July 2022

htmlwidgets for R

The htmlwidgets package enables the integration of JavaScript-based data visualisations into R, allowing users to generate interactive plots directly at the R console, embed them within R Markdown documents or Shiny applications and develop custom widgets that bridge R and JavaScript seamlessly. Tools such as flexdashboard facilitate the arrangement of multiple widgets into flexible layouts, while crosstalk supports linking visualisations for coordinated interactions. The framework also provides guidance for creating new widgets, expanding the range of available visualisations and enhancing their use in analytical workflows.

14:05, 29th June 2022

Semantic Versioning 2.0.0

Semantic Versioning offers a structured approach to version numbering, enabling developers to communicate changes clearly and manage dependencies effectively. By adhering to a formal specification, version numbers become meaningful indicators of compatibility and stability.

The system divides updates into major, minor and patch levels, with major versions reserved for backward-incompatible changes, minor for new features and patch for bug fixes. This clarity allows dependent projects to specify ranges that ensure compatibility without requiring constant updates.

The specification emphasises the importance of a well-defined public API, particularly when releasing version 1.0.0, which signals a stable foundation for users. During initial development (0.y.z), rapid iteration is encouraged, but once the API solidifies, careful consideration of backward compatibility becomes essential. Deprecating features requires documentation and a minor version release to allow users time to adapt before removal in a major update. Practical challenges, such as accidental versioning errors or managing dependencies without altering the public API, are addressed through guidelines on corrective releases and evaluating the impact of changes.

While the system may seem rigid, it encourages thoughtful development, ensuring that incompatible changes are introduced only when necessary. By linking to the specification in project documentation, developers invite others to benefit from consistent practices, reducing the friction of dependency management. The approach avoids arbitrary versioning, prioritising transparency and predictability. It acknowledges the complexity of real-world software but provides a framework to navigate it systematically, ensuring that updates are both intentional and manageable.

16:23, 16th June 2022

Python Check If File Exists

In Python, two standard approaches exist for checking whether a file exists before performing operations on it. The first uses the exists() function from the os.path module, which accepts a file path as its argument and returns True if the file is found or False if it is not. The second uses the is_file() method from the Path class within the pathlib module, available since Python 3.4, which follows an object-oriented approach and behaves in the same way. When specifying file paths with either method, forward slashes should be used as separators, as this works consistently across Windows, macOS and Linux.

  • The content, images, and materials on this website are protected by copyright law and may not be reproduced, distributed, transmitted, displayed, or published in any form without the prior written permission of the copyright holder. All trademarks, logos, and brand names mentioned on this website are the property of their respective owners. Unauthorised use or duplication of these materials may violate copyright, trademark and other applicable laws, and could result in criminal or civil penalties.

  • All comments on this website are moderated and should contribute meaningfully to the discussion. We welcome diverse viewpoints expressed respectfully, but reserve the right to remove any comments containing hate speech, profanity, personal attacks, spam, promotional content or other inappropriate material without notice. Please note that comment moderation may take up to 24 hours, and that repeatedly violating these guidelines may result in being banned from future participation.

  • By submitting a comment, you grant us the right to publish and edit it as needed, whilst retaining your ownership of the content. Your email address will never be published or shared, though it is required for moderation purposes.