I want to execute Makefile on one of my Ansible provisioned servers with flag -e but Ansible make module does not seem to support this (just key-values)
Is there any other way of doing that, other than: "command: make -e my_target"?
Ansible make module docs
There doesn't appear to be any code in the module to support what you are looking for. If you want the module to be extended, I'd suggest raising an issue against it at github.com/ansible.
Related
I'm pretty new to Ansible, just a day old and while trying out some basic ad hoc commands, I noticed that in order to create a directory on a group named nodes, both of the following commands worked.
METHOD 1
ansible nodes -a "mkdir /BYANSIBLE_2"
METHOD 2
ansible nodes -m file -a "path=/BYANSIBLE_3 state=touch"
According to the documentation, -a means module arguments, so why does METHOD 1 work ?
According to my understanding merely providing the arguments of a module without specifying the module itself shouldn't work (unless there is some implicit default).
Also, as a newbie, should I focus on METHOD 1 or METHOD 2 when using adhoc commands ?
Ansible uses the module ansible.builtin.command by default if no module is provided in the command line . This module just runs commands on the remote nodes command line, which is why "mkdir path" works. for you. The argument for this module is, well, a command.
On method 2 you are actually calling a specific module "file" that has its own definition of the arguments required. The argument for this module is just the path that needs to be created.
The method that you use depend on the case. If you are testing commands on remote nodes, method 1 would be my go to, since is faster than explicitly adding the module name. Method 2 is better in the sense that is more explicit in intention.
But more importantly, i try to keep ad hoc commands for very small tests and tasks. Ansible is about automating and scaling to me, so i try to create playbooks whenever possible.
You can read more in the following link:
https://docs.ansible.com/ansible/latest/user_guide/intro_adhoc.html
I'm trying to find a simple method of running an ansible playbook from within a ruby script.
My script checks various conditions, and - if those conditions a met - runs an ansible playbook.
I thought I could run the playbook via backticks using the kernel module. However I'm unsure how I could parse the output to tell if I had success. Does anyone have a method, wrapper or library to do this? Searching the web only resulted in information about how to deploy ruby with ansible playbooks, not the other way around.
If you want to read the output of a command you need to use Open3.
For example:
require 'open3'
output, status = Open3.capture2('ansible', '...')
Where you split out the arguments to the ansible command separately to avoid ugly shell-interpolation issues.
There's a variety of tools in the Open3 module that help with things like streaming output, checking STDERR and more.
If you don't mind a dependency then you can use tty-command:
require 'tty-command'
cmd = TTY::Command.new
result = cmd.run('ansible ...')
puts result.out.chomp
I am hacking together an Ansible solution to deploy a notify.sh bash script as part of a pam.d / pam_exec configuration.
The script uses a bunch of variables that I have been told need to be a part of a separate yml file (so others can change or update them) instead of being defined in the script directly, which is what I am normally used to doing.
I have constructed the vars file where I have defined the variables which the script should be using at runtime.
Now my problem is that I want to be able to access the ansible variables in their standard format {{my_variable}} from the bash script which I am deploying.
Is this even possible? If it isn't possible, what are your suggestions for inserting the variables into the script after its installed?
I have a feeling I am close to the answer, but scowering Ansible help files has not yielded anything yet.
The only thing I kinda figured would be to use the lineinfile module to update the shell script after its already installed, but I feel like this maybe a bit too hacky and there is probably a more elegant solution here.
I appreciate any and all answers.
Sure – anything in /vars/main.yml is automatically available, or you can load a custom file with http://docs.ansible.com/ansible/include_vars_module.html. Then, use a template and deploy your script like this:
template:
src: script_template.j2
dest: "path/notifiy.sh"
mode: 700
I am looking to automate an interactive install process with ansible. This install does not have a silent install option or does not take command line arguments for the interactive questions. The question involve setting a folder location, making sure folder location is right etc for which answers might be default or custom.
I looked into the expect module of ansible but seems like it does not solve my purpose.
- expect:
command: passwd username
responses:
(?i)password: "MySekretPa$$word"
I don't need the command but it's required. Instead I am looking for something that could regex Are you sure you want to continue [y|n]? [n]: for which I want to send the default out By sending return or typing n as a response and for example Backup directory [/tmp] for which the response would be Carriage return.
I don't need the command but it's required. Instead I am looking for something that could regex Are you sure you want to continue [y|n]? [n]:
The module requires a command because you have to run something to get any output.
You obviously do have a command in mind, because you've run it manually and seen the output it produces. That's what you should be plugging into the module.
Alternatively, you can write a pexpect script yourself and use the command or shell modules to run it.
I've figured out a way that works for me. I piped in the arguments to the shell script which when run manually needs the answers. Like ./shell.sh <<< 'answer1\nanswer2\n' which works perfectly for me. This I have added to the task.
..in the following shell script?
$USER1$=/usr/lib/nagios/plugins
As far as i know variable defining is done as-
export USER1=/usr/lib/nagios/plugins
Source:
Ok, the command works. Now I have to implement it into Nagios. Because
all my "local" command not installed by the package-manager shall be
in /usr/lib/nagios/plugins_local I define a $USER2$ variable for this
path:
# vim resource.cfg
...
# Sets $USER1$ to be the path to the plugins
$USER1$=/usr/lib/nagios/plugins
# my own check-commands live here:
$USER2$=/usr/lib/nagios/plugins_local
$USERn$ (more specifically, $USER1 to $USER255$) is the way to declare a user-defined Macro in Nagios.
See also "Understanding Macros and how they work."
More specifically and more interestingly this is a good way to hide usernames/passwords needed withing database/http checks for instance.
This means that you can attempt soemthing like the following directly in your configuration files and thus you do not fear that you are committing or backing up usernames/passwords.
./nrpe -c check_http -H $IP -a $USER1$:$USER2$ -u $LINK
An aside: Unfortunetly Nagios only supports up to 32 of the USER variables.