Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run a module locally

Tags:

ansible

I'm developing a smoke test playbook which simply goes through and ensures that I get a HTTP 200 out of all of our servers.

I was originally doing this:

---
- hosts: prod
  gather_facts: no
  tasks:
      - name: smoke test
        uri: url=http://{{ inventory_hostname }}/ status_code=200

The problem here is that these servers apparently don't have httplib2 installed on them, so the URI command fails.

Is there a way for me to run the uri module on my local machine to the remote machines to just run through all of them and curl each one? I'd like to use a module if possible, because it's easier to check that the return code is exactly what I want.

like image 263
Naftuli Kay Avatar asked Nov 18 '15 21:11

Naftuli Kay


People also ask

How do I run a node module locally?

Simply run: $ npx [options] <command>[@version] [command-arg]... By default, npx will check whether <command> exists in $PATH , or in the local project binaries, and execute that.

What is a local module?

Local Modules: (Custom or User Defined Modules) Local modules are mainly used for some specific purpose in projects and locally available in separate files or folders within project.


1 Answers

You can delegate any task to localhost or another remote host with delegate_to:

- name: smoke test
  uri: url=http://{{ inventory_hostname }}/ status_code=200
  delegate_to: localhost

Also, there is the local_action module, but I prefer the delegate_to way.

- name: smoke test
  local_action: uri url=http://{{ inventory_hostname }}/ status_code=200
like image 159
udondan Avatar answered Sep 17 '22 15:09

udondan