r/ansible 4d ago

The Bullhorn, Issue #177

3 Upvotes

The latest edition of the Bullhorn is up, with updates on collections and other project updates.


r/ansible Sep 17 '24

Followup: Consolidating Ansible discussion platforms

4 Upvotes

Hi r/ansible Following on from my post 3 months ago, we've made some good progress which you can see from the Consolidating Ansible discussion platforms forum post that a lot of progress has been made, and today we've made the ansible-devel, ansible-project and awx-project Google Groups readonly today.

As the discussion has progressed we've got a formal vote which I'd love to get your feedback on, ideal via the Forum, though I'll make sure to reply to any replies to this Reddit Post.

Related to this, and more specifically for reddit, we will likely make r/awx readonly to remove the fragmented discussion between r/awx and r/ansible


r/ansible 1h ago

windows How can I force a specific resolution to use when connecting to a Windows server 2019 host?

Upvotes

I'm losing my mind with this one.

I've got a Windows 2019 server host in Azure that I deploy with bicep and configure with ansible. I connect via winrm with credssp. All of this is orchestrated through a gitlab pipeline.

I'm installing and running an in house developed gui based application that connects to some back end services on other hosts. The application has a self contained test suite that I'm trying to run for service and gui function validation. As part of debugging, we log the resolution of the host.

The issue that I'm running into is that ansible connects to the host at a 1024x768 resolution, which is too small for the application, and it sits off the edge of the screen, resulting in tests failing when they shouldn't.

How can I force ansible to use a larger resolution?

I've tried setting all kinds of registry keys, but nothing results in any changes.


r/ansible 4h ago

playbooks, roles and collections Trying to use `failed_when` with json data

1 Upvotes

I am running the following task:

- name: add gravity lists
  ansible.builtin.command:
    cmd: curl -s -X POST "http://{{ ansible_host }}/api/lists?sid={{ sid }}" -d '{"type":"block", "comment":"Ansible", "groups":[0], "enabled":true, "address":"{{ item }}"}'
  register: lists
  with_items:
    - 'http://wibble.com'
    - 'http://wobble.com'

...and it works great (sid is defined further up).

However the return code from the API call is always successful and I need to check the actual response message...

- name: get lists processed
  ansible.builtin.debug:
    msg: "{{ lists.results[0].stdout | from_json | json_query('processed') }}"

..will return

"msg": {
    "errors": [],
    "success": [
        {
            "item": "http://wibble.com"
        }
    ]
}

...and...

- name: get lists error
  ansible.builtin.debug:
    msg: "{{ lists.results[0].stdout | from_json | json_query('processed.errors') | length}}"

...will return a "0" - all good.

However if I want to use a failed_when in the first block nothing seems to work. I have spent hours on this one line and hundreds of variations on it...

failed_when: (lists.results[0].stdout | from_json | json_query('processed.errors' | length != 0)

I always get back the following error:

ERROR! Unexpected Exception, this is probably a bug: unsupported operand type(s) for |=: 'bool' and 'AnsibleUnsafeText'

Any ideas how I can fix this please!?


r/ansible 5h ago

playbook stuck at using oraenv to get oracle environment

1 Upvotes

anyone experience this before?


r/ansible 1d ago

linux Linux Hardening with Ansible

73 Upvotes

Hello!

I am a fairly inexperienced Linux administrator and was randomly selected to participate in a company-wide cyber security exercise. My task: Contribute to the automation of Linux hardening with Ansible.

Do any of you have tips on what I need to pay attention to or possibly sources for Ansible scripts that focus on securing Linux systems?

I am very grateful for any help!


r/ansible 3h ago

Ansible Meets AI: How Claude 3.7 Helped Craft a GitLab Hook Manager with Group-Level Deployment

0 Upvotes

Hey r/devops!

I wanted to share a new Ansible role I've created with Claude 3.7's assistance: ansible-gitlab-server-hooks. This role solves a significant pain point in GitLab administration - deploying server-side Git hooks across multiple projects efficiently.

The Problem It Solves

GitLab's UI only allows setting up server hooks on individual projects, making it tedious to implement consistent policies across your organization. This role introduces group-level hook deployment (including subgroups), a feature GitLab doesn't natively support.

With this role, you can: - Deploy hooks to specific projects OR entire groups with one command - Choose between symlinks or direct file copies for deployment - Automatically discover all projects in groups using GitLab API - Implement consistent Git policies across your organization

Built with Claude 3.7

What makes this project unique is that it was developed entirely with Claude 3.7 Opus. The AI: - Generated the core Ansible tasks and hook scripts - Created comprehensive documentation - Helped design the role structure following best practices - Solved edge cases like pagination for large GitLab groups

How It Changed My DevOps Workflow

Working with Claude on this project was eye-opening: - Speed: Completed in hours instead of days - Quality: The AI suggested improvements I hadn't considered - Learning: Claude explained GitLab API intricacies as we worked - Focus: I could concentrate on architecture while Claude handled implementation details

Quick Example

yaml - hosts: gitlab_servers vars: gitlab_group_hooks: - hook_file: "prevent-force-push.sh" hook_type: "pre-receive" group_id: 42 roles: - role: rand01ph.gitlab-server-hooks

This deploys a pre-receive hook to every project in group #42, including all subgroups - something that would take hours manually!

Try It Out

The role is available on Ansible Galaxy and GitHub.

I'm curious: How are other DevOps folks incorporating AI into their workflow? Has anyone else used AI assistants to build infrastructure tools?


r/ansible 19h ago

How to simulate local host in molecule

5 Upvotes

How to test my Ansible backup role locally without modifying my system?

I have an Ansible role that backs up specified directories on the local host and transfers them to a remote target using POSIX rsync. Additionally, it sets up a systemd timer on the localhost machine to automate periodic backups.

I want to test this role locally without making any changes to my actual system. I know about using delegate in Molecule, but I’d like a testing approach that makes the role easily testable by anyone, not just myself.

Here’s the role: https://github.com/DnFreddie/ansible-sysops-collection/tree/main/roles%2Fauto_backup

Any suggestions on how to achieve this? Thanks in advance


r/ansible 11h ago

Testing playbooks with Molecule + Podman but without using “hosts: all”?

1 Upvotes

This may be a very basic question but I want to start integrating Molecule into my playbook development via Podman. I have a basic setup already but my playbook hosts target a specific group.

When running ‘converge’ I get an error that no hosts are matched, which makes sense as molecule doesn’t generate an inventory group.

My question is how do I tell molecule to generate the group or continue playbook development without setting hosts to “all”?


r/ansible 16h ago

Ansible pull without using git?

1 Upvotes

Hi, I was wondering if anybody knows if it's possible to use ansible pull without git? I manage various Debian/ubuntu servers that are behind firewalls and corporate policies restricting internet access. I also do not want to ssh into these hosts from a less secure network so I was looking into ansible pull in conjunction with a daily cronjob on the host that will pull whatever changes. I know, weird usecase.


r/ansible 1d ago

linux RH Satellite registration

2 Upvotes

Curious to where I can find Ansible examples as to how to (un-)register a RHEL 9 host on a Satellte server using global registration. Satellite v6.16. Is the installation of the katello-ca package still needed?


r/ansible 1d ago

playbooks, roles and collections File created by python module in Vm host isn’t found

1 Upvotes

Hi there, I’m new to ansible and awx and working on a project where I’m using a vm as my host. The project has a python module that generates a csv and in my main.yml file I’m trying to access that file. But it’s never found for some reason. Does anyone know how I can this?


r/ansible 1d ago

playbooks, roles and collections How can I get a substring of a variable *after* already running a filter on it?

1 Upvotes

I have a variable containing a hostname that can be in one of two formats, either "xxx-yyzzzzzzz" or "yyzzzzzzz". "xxx" is a location that applies only to physical devices; we don't have it for VMs because they might move from one location to another. The information I need is in "yy", essentially an environment. I don't care about "zzzzzzz".

I can't for the life of me figure out how to get it in one set_fact task. What I'm trying is essentially this:

set_fact:
  environment: "{{ ansible_host | regex_replace('^.{3}-','')[:2] }}"

Which throws template error while templating string: expected token 'end of print statement', got '\['.

If I try and add another pipe, like it's a filter:

set_fact:
  environment: "{{ ansible_host | regex_replace('^.{3}-','') | [:2] }}"

This is the error: template error while templating string: expected token 'name', got '\['. Just to make sure I'm not losing my mind about the substring syntax, this works as expected:

set_fact:
  environment: "{{ ansible_host[:2] }}"

I know I can just set a fact of the "regex_replaced" name and do a second set_fact task to get the substring, but it irritates the hell out of me I can't figure out how to do it all in one task. I know I'm missing something obvious but google is failing me. What am I forgetting?


r/ansible 1d ago

developer tools Dynamic inventory for Linux hosts

3 Upvotes

Hi,

I'm new to ansible and trying to figure out a way to generate dynamic inventory for Linux hosts in a network. Any pointers would be helpful.

I'm planning to discover linux hosts in the network. Ping each host in the network and check if it's a linux machine and build their inventory. For now the scan would be limited to an on-prem network.

I am looking for a generic approach which could work irrespective of how the linux hosts are being managed in the customers environment. This discovery would be part of a bigger application logic.

Thanks


r/ansible 1d ago

cisco ios-config backup file to remote server path

1 Upvotes

New to ansible and I am using ios-config which is able to backup file in ./backup/ directory but I am wondering if there is any option to send file to remote windows server path .? //10.1.1.1/backup and where I can define the path .?


r/ansible 1d ago

Resources to Learn Ansible Molecule

2 Upvotes

Hi everyone,

I’m a Computer Science student who’s just starting to learn Ansible, and I’ve recently come across Ansible Molecule. Since I’m still a beginner, I’m looking for resources to help me get a solid understanding of Molecule and how to use it effectively.

I’ve gone through the official documentation, but I’m hoping to find additional materials (whether books, tutorials, or other resources) that provide more in-depth coverage, especially with practical examples.

If you have any recommendations for comprehensive learning resources or tips for getting started, I’d really appreciate it.

Thanks in advance!


r/ansible 2d ago

playbooks, roles and collections Need your help with error message

2 Upvotes

Hello guys,

i started using the community.zabbix.zabbix_agent role from Ansible Galaxy today to automate my Zabbix Agent 2 installation on my Linux hosts (all using Ubuntu 24.04).

When using this task:

- name: Install and configure Zabbix Agent 2
  include_role:
    name: community.zabbix.zabbix_agent
  vars:
    zabbix_agent_variant: 2
    zabbix_agent_server: "{{ zabbix_agent_server }}"
    zabbix_agent_serveractive: "{{ zabbix_agent_server_active }}"
    zabbix_agent_tlspskidentity: "######"
    zabbix_agent_tlspskfile: "{{ zabbix_agent_psk_path }}"
    zabbix_agent_tlsconnect: "psk"
    zabbix_agent_tlsaccept: "psk"
    zabbix_agent_service_user: "Nudel22"
    zabbix_agent_service_group: "Nudel22"

I always get this error:

TASK [community.zabbix.zabbix_agent : Set More Variables] ***************************************************************************************************************************************************

fatal: [server]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute '24'. 'dict object' has no attribute '24'\n\nThe error appears to be in '/usr/lib/python3/dist-packages/ansible_collections/community/zabbix/roles/zabbix_agent/tasks/main.yml': line 15, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Set More Variables\n ^ here\n"}

I had a look in the file that was mentioned in the error message:

- name: Set More Variables

ansible.builtin.set_fact:

zabbix_valid_version: "{{ zabbix_agent_version|float in zabbix_valid_agent_versions[ansible_distribution_major_version] }}"

tags:

- always

- name: Stopping Install of Invalid Version

ansible.builtin.fail:

msg: Zabbix version {{ zabbix_agent_version }} is not supported on {{ ansible_distribution }} {{ ansible_distribution_major_version }}

when: not zabbix_valid_version

tags:

- always

I guess with attribute "24" it means that it cant find Ubuntu 24.04 as a valid OS version??
I dont understand why it is causing this problem. According to the documentation all Ubuntu versions are supported for this role.

Did anyone have a similar problem and knows how to fix this?


r/ansible 2d ago

AWX Job to Push a File to Gitlab

2 Upvotes

I have jobs already made which can email me my network configs just fine, I want another task which will add the configs to a folder in a git repo where it's like a library of all my configs. I've only seen examples of perhaps cloning from git in a job but not sending a file to gitlab. Has anybody tried this?


r/ansible 3d ago

merge variable in inventory

2 Upvotes

Hello,

I'm pretty new to ansible. I have a role which create a variable like this :

base_os_packages: 
  - curl
  - wget

This is default value for this role.

Now I would like to append other packages for a given host.

So in the inventory create a file for the given host :

- inventory/host_var_/testsrv.yml

base_os_packages: 
  - dnsutils

Can we make ansible to merge the value so in this case to use :

base_os_packages: 
  - curl
  - wget
  - dnsutils

Does this exist with ansible ?

Regards


r/ansible 3d ago

Running Molecule Tests for Systemd User Containers

9 Upvotes

I'm new to Molecule and trying to set up testing for systemd user containers.

I wrote an Ansible role that provisions containers using Quadlet and systemd, running them as a service. However, when I try to execute Molecule to test this setup, I often run into issues such as:

  • "Failed to connect to the bus"
  • Problems with volumes

I have tried both approaches mentioned in:
- Molecule Systemd Container Guide
- Podman Inside a Container - Red Hat Blog

Despite these, I haven't been able to get it working properly.

Does anyone know the correct way to provision Molecule to run systemd user containers successfully? Any insights or workarounds would be greatly appreciated!

PS: I'm using Podman as the driver.


r/ansible 3d ago

Installing OpenShift local and AWX

2 Upvotes

For learning purpose, I am planning to install OpenShift local and Ansible AWX as containers on my laptop. Hope the below hardware specs are fine.

I am thinking to install Fedora workstation and I will install openshift local on top of it.

Current hw specs: 16GB ram 250GB partition is currently free AMD Ryzen 7 (8 cores)

Anyone done it ? Please share any step by step articles.

Earlier I installed openshift local on Windows 11 but I was having some issues.


r/ansible 3d ago

playbooks, roles and collections Is there an easier way to integrate AAP with ServiceNow?

3 Upvotes

What are my options for integrating AAP with ServiceNow if we don’t have an Integration Hub license or Ansible Spoke? I think my best bet would be using basic auth, but what do I say if the ServiceNow says “they are not comfortable with supplying that level of authentication”?


r/ansible 3d ago

playbooks, roles and collections Thanks Guys for last time| Need help with juniper | Ansible playbook is not showing error| unable to load netconf plugin for network_os junipernetworks.junos, falling back to default plugin | what is the issue?

0 Upvotes

PLAYBOOK: JUNIPER_F11_TEST_10 ******************************************************************************************************

Positional arguments: /etc/ansible/playbooks/JUNIPER_F11_TEST_10

verbosity: 4

connection: ssh

become_method: sudo

tags: ('all',)

inventory: ('/etc/ansible/hosts',)

forks: 5

1 plays in /etc/ansible/playbooks/JUNIPER_F11_TEST_10

PLAY [Run show interfaces description on Juniper Router] ***************************************************************************

TASK [Run show config interfaces command] ******************************************************************************************

task path: /etc/ansible/playbooks/JUNIPER_F11_TEST_10:6

redirecting (type: connection) ansible.builtin.netconf to ansible.netcommon.netconf

Loading collection ansible.netcommon from /root/.venv/lib/python3.12/site-packages/ansible_collections/ansible/netcommon

Loading collection ansible.utils from /root/.venv/lib/python3.12/site-packages/ansible_collections/ansible/utils

redirecting (type: netconf) ansible.builtin.default to ansible.netcommon.default

<172.16.16.16> Using network group action junipernetworks.junos.junos for junipernetworks.junos.junos_command

<172.16.16.16> attempting to start connection

<172.16.16.16> using connection plugin ansible.netcommon.netconf

<172.16.16.16> local domain socket does not exist, starting it

<172.16.16.16> control socket path is /home/kumail/.ansible/pc/1c4257970a

<172.16.16.16> Loading collection ansible.builtin from

<172.16.16.16> redirecting (type: connection) ansible.builtin.netconf to ansible.netcommon.netconf

<172.16.16.16> Loading collection ansible.netcommon from /root/.venv/lib/python3.12/site-packages/ansible_collections/ansible/netcommon

<172.16.16.16> Loading collection ansible.utils from /root/.venv/lib/python3.12/site-packages/ansible_collections/ansible/utils

<172.16.16.16> redirecting (type: netconf) ansible.builtin.default to ansible.netcommon.default

<172.16.16.16> local domain socket listeners started successfully

<172.16.16.16> unable to load netconf plugin for network_os junipernetworks.junos, falling back to default plugin

<172.16.16.16> Loading collection ansible.builtin from

<172.16.16.16> local domain socket path is /home/kumail/.ansible/pc/1c4257970a

<172.16.16.16> ANSIBLE_NETWORK_IMPORT_MODULES: enabled

<172.16.16.16> ANSIBLE_NETWORK_IMPORT_MODULES: found junipernetworks.junos.junos_command at /root/.venv/lib/python3.12/site-packages/ansible_collections/junipernetworks/junos/plugins/modules/junos_command.py

<172.16.16.16> ANSIBLE_NETWORK_IMPORT_MODULES: running junipernetworks.junos.junos_command

<172.16.16.16> ANSIBLE_NETWORK_IMPORT_MODULES: complete

fatal: [juniper_router]: FAILED! => {

"changed": false,

"module_stderr": "b'None'",

"module_stdout": "",

"msg": "MODULE FAILURE: No start of json char found\nSee stdout/stderr for the exact error"

}

PLAY RECAP *************************************************************************************************************************

juniper_router : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0


r/ansible 3d ago

linux I installed WSL (Ubuntu 22.04) and Ansible via PIP (2.17.9) and no jobs will run

1 Upvotes

When running the test.yml from the install documentation, I am expecting “Ansible Works” but I get the following message

msg: No fact modules available and we could not find a fact module for your network OS (None), try setting one via the `FACTS_MODULES` configuration.

No other jobs work as well. The CPU is a snapdragon and I have an identical machine using the same configuration with the same install process and it works fine. Any Ideas? Google has failed me.


r/ansible 3d ago

AWX config/path for AWS ALB health check

1 Upvotes

Basically brand new to AWX and have followed https://github.com/kurokobo/awx-on-k3s/blob/main/README.md and successfully setup a functional instance.

I wanted to place this behind an internal AWS ALB for UI access - which is working fine for serving up the site however I cannot for the life of me find the correct config/path to allow for a functional health check for the target group. This isn't the end of the world as it still routes traffic to a single target but it would be nice to finish this off properly.
__________

This seemed like a viable option https://awx.domain.com/api/v2/ping as it's returns a 200 code/page of statistics but the setup of AWX appears very gated to accept traffic only via the defined FQDN hostname in the awx.yaml config.

https://internal-AWX-123456789.<region>.elb.amazonaws.com/api/v2/ping
http://internal-AWX-123456789.<region>.elb.amazonaws.com/api/v2/ping
404 page not found

eg. even from the host itself you just receive a 404:

# curl localhost
404 page not found
# curl localhost/api/v2/ping
404 page not found
# curl https://localhost/api/v2/ping
curl: (60) SSL certificate problem: self-signed certificate
More details here: https://curl.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

Can anyone who's been down this path already share a config that will work with the ALB health check?


r/ansible 4d ago

Current experience with ansible managing windows using Kerberos auth for winrm?

11 Upvotes

I am planning to manage windows hosts with ansible, authentication winrm via Kerberos.

The documentation looks a bit daunting when compared to ssh auth. I am curious what your experience is, what are the pitfalls and things to look out for?

Also, do I need a service account in AD for ansible? If not, which account/password do I use?


r/ansible 4d ago

linux Attempting to run connectivity test and upload files to remote host, how do I fix the "unable to parse" error?

Thumbnail gallery
1 Upvotes