ansible.posix.synchronize task failed with error 'Connection' object has no attribute '_new_stdin'

I have open sourced some Ansible roles I use for my personal projects. Everything was working well until one day running my playbook would always fail on the ansible.posix.synchronize task.

TASK [websites : push example.com contents] **************************************************************************************************************************
[ERROR]: Task failed: 'Connection' object has no attribute '_new_stdin'
Origin: /Users/aikchar/ansible-roles/websites/tasks/rhel.yml:18:3

16   become: yes
17
18 - name: "push {{ domain_name }} contents"
     ^ column 3

fatal: [example.com]: FAILED! => {"changed": false, "msg": "Task failed: 'Connection' object has no attribute '_new_stdin'"}

Read more …

Use awk Script to Modify a File

I had to modify a complex file in a Dockerfile. While sed was working, it wasn't very readable. I didn't want to use Python because then I'd have to install it unnecessarily. I ended up using awk because of its availability and its purpose that met my needs.

Read more …

Run pytest Tests Easily Locally and in Pipeline

At my day job we write Ansible custom modules and filter plugins. Since these are pure Python pieces of code, we also write unit tests for them. We love pytest and all our tests are written in it.

The challenge we faced was how to easily run these tests locally on developer machines and in CI/CD pipeline. The solution was easy enough once we figured out how to meld Python with make.

Read more …

Test Go Function That Calls Another Function

A very popular question people ask when working with Go and HTTP clients is how to test the code with go test. You will see many mentions of interfaces, test doubles (stubs, mocks, fakes, etc.), httptest, and so on.

I had a similar problem but it was like this: a function in module A was doing some work on the results returned by a function in module B. In other words, module A was depending on module B. Module B is expected to have its own tests, which must not be repeated in the tests written for module A; why duplicate the effort? How could I test module A without also testing module B in the tests written for module A?

Read more …

Build Python 3.11 From Source With TLS/SSL on CentOS 7

Building Python 3.11 from source on CentOS 7 is straightforward but it is tricky when we want to build with TLS/SSL support. The reason is that OpenSSL version (1.0.2k) in CentOS 7 is older than the minimum required by Python 3.11 i.e. 1.1.1k. This is not an unsurmountable problem because the newer version is available in the EPEL repository.

Read more …

Ansible runs task in role even when condition is false

I ran into a perplexing problem where Ansible was running a task in a role even if the role had a when condition which was resolving to false. Plus the task was failing.

To visualize it better, one task (not all) was running in the role symptom in the example playbook below,

---
- hosts: all
  roles:
    - role: symptom
      when:
        - false

Read more …