Bootstrap FreeKB - Ansible - Run a script using the script module
Ansible - Run a script using the script module

Updated:   |  Ansible articles

If you are not familiar with modules, check out Ansible - Getting Started with Modules.

Typically, the shellcommand, or script modules are used to invoke a command on a managed node (e.g. target systems).

Python (e.g. /usr/bin/python) needs to exist on the managed node to use these modules.

Python is not need to use these modules. 

  • script (this article)
  • raw 

One thing that's pretty cool about this module is that the script you want to run will be stored somewhere on your control node (that's your Ansible server) but the script will actually be executed on each target system.

---
- hosts: all
  tasks:
  - name: my script
    script:
      cmd: /path/to/your/script.sh
...

 

Optionally, you can include command line flags too.

---
- hosts: all
  tasks:
  - name: my script
    script:
      cmd: /path/to/your/script.sh --foo bar
...

 

If the script requires certain environment variables to be set, environment can be included.

---
- hosts: all
  tasks:
  - name: my script
    script:
      cmd: /path/to/your/script.sh --foo bar
    environment:
      LC_ALL: en_US.utf-8
...

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 1a54df in the box below so that we can be sure you are a human.