Running shell script using Ansible

Hello All,

I need to execute shell script using ansible but need to pass arguments to this script without using -e arguments.

Is there anyway if we can read the file kept inside the package and read those variables in ansible playbooks and pass it to shell script.

Let me know if there is anyway to achieve this.

Regards
Amit

The shell module just executes what you tell it to - including arguments. So no problem there. Read again
https://docs.ansible.com/ansible/latest/modules/shell_module.html.

The -e arguments to ansible are a way to provide/override variables. Don’t mix those up.

You mention things like “reading a file which is kept in a package”. That is something different than running a shell command.

So, could you please tell clearly:

  • What you are trying to achieve.

  • How you are doing this.

  • What problems you encounter.

  • Which command did you run, and what output did you get from that (copied as text, not as images/attachments/screenshots)

  • What the relevant tasks/playbooks/code/variables look like

Hello Dick,

Thanks for your response.

I am trying to perform installation on I server (Microstrategy component) and binaries along with shell script should be available in bit bucket repository.

Ansible should be able to pull that tar file and unzip it.

After this it should be able to trigger the shell script and for this script it needs some parameters to be passed.

I have seen in documentation that we can pass these parameters in play book it self however that will be hard coding directly in the playbook, hence I was thinking to read it from file and pass it to shell script.

Let me know if you need any further details to this.

Appreciate your inputs on this.

Regards
Amit

Hi

It sounds like you are at the very beginning and just exploring options, as you don’t have any ansible code yet.
You might look at the slurp module to fetch remote content, examine that and use it later in the shell command.

Dick

Hi Dick,

I am at the starting point but I don’t want to fetch package from node but have to pull from bit bucket repository which is similar to git.

Regards
Amit

Aha so git it is then