setting value in cgroup's cpu.rt_runtime_us with ansible - ansible

I am setting a value on cpu.rt_runtime_us with echo command, like:
echo 950000 > /sys/fs/cgroup/cpu,cpuacct/user.slice/cpu.rt_runtime_us
It is on Redhat OS.
Is there more elegant way to configure it?
I'd like to use it in an ansible playook and I don't like using shell task and run this command every time playbook is run.
Appreciate any good proposal or a good practice for this kind of setting from ansible.

Related

How to set application credential details in CI?

How to set application credential details in buildkite so that it can be used as part of tests?
Any help?
thanks in Advance
The easiest way is to store them in an agent environment hook, which is a script file you need to put on the host running the agent, and is invoked just before every job the agent runs:
# /etc/buildkite-agent/hooks/environment
set -eu
echo "--- :house_with_garden: Setting up the environment"
export APPLICATION_PASSWORD="xxx"
and then use them in your pipeline commands from the environment:
# .buildkite/pipeline.yml
steps:
- label: Run tests
command: ./run-tests --password="$$APPLICATION_PASSWORD"
The double-dollar escapes the variable for pipeline upload, making sure that the password is not interpolated into the YAML and then submitted to buildkite.com. It will then be interpolated once the agent runs the command.
You could also access $APPLICATION_PASSWORD within your script to avoid mentioning it in the yaml at all.
The agent environment hook works best if you're running long lived agents, or use something like the elastic-ci-stack-for-aws which has a shared environment hook for this sort of thing:
https://github.com/buildkite/elastic-ci-stack-for-aws#build-secrets
but there are a few other options, too:
https://buildkite.com/docs/pipelines/secrets

How can I write a bash command that takes 15 mins to run before another command is executed in Ansible?

I am trying to update the version of some software through Ansible for a server.
- name: upgrade firmware version
shell: bash -x bmc_firmware_update.sh -k -F BMC_0204.00.bin_enc -s 1
this could take about 15 mins to run. I have another command to run after that, i.e
-name: something else
shell: bash -x bmc_firmware_update.sh -k -F BMC_0204.00.bin_enc -s 2.
I came across wait_for: timeout=300 but I want to know if there is a better way to go about making sure that the first one is successfully completed before the second shell command is run. Please advice!
Apparently this has nothing to do with Ansible.
Programs runs in foreground by default.
#sorin this is Ansible related!
#op; You can append to the firmware_update.sh script that when finished, it writes a certain value to specific path. Then let Ansible check that file and if that value is there. If it is, continue, if not, retry.
Another possibility is to write the logic in the bash scripts themselves.

How to avoid 'Escalation succeeded' when serving my project?

I have been working now for 2 weeks on a playbook to deploy CKAN with Ansible on RHEL. I manage to get the site up and running with:
- name: test ckan
shell: ". {{ckan_user.home_path}}/{{ckan_site_name}}/bin/activate && paster serve /etc/ckan/{{ckan_site_name}}/development.ini"
args:
chdir: "{{ckan_user.home_path}}/{{ckan_site_name}}/src/ckan"
The result is that the playbook is stuck in an infinite loop saying:
'Escalation succeeded'.
I'm sure that there is an easy fix, but I can't find it...
Any ideas are more than welcome.
Add “&& exit” or something after your shell command.
Also, register the task, then read it at the next task to see what the output value is.
In this way, you can stop or continue the play based on the output of the task.

How to save only the play recap of Ansible to a file?

The question is as the title said, how to save only the "play recap" of ansible to a file or variable?
I am trying to make a web UI using Flask to make the user use ansible easier without writing any script or playbook, just write some hosts' IP address and click on what you want to do and flask/python script will call and play the premade playbook. The problem is I can't really tell the user whether the task is successfully done or not, because it only shows on Linux terminal. Therefore I want to "catch" only the "play recap" of the playbook and show it on a web page to tell the user the result.
Since the environment and setup isn't further described, it is assumed you are just running ansible-playbook ... from CLI and send the output to STDOUT.
In such case you could use commands like
ansible-playbook deployment.yml | tee deployment.log
sed -n '/PLAY RECAP/,$p' deployment.log
and proceed further from there.
Thanks to
Linux - grep from certain lines to the end of file
Is there a way to print only Ansible PLAY RECAP into CSV or HTML file and mail it?
Regarding an own plugin, you may take advantage from Ansible Issue #14367 "Show aggregated playbook execution recap at the bottom of play recap" or Access Ansible playbook results after run.

Laravel Envoy and bash prompt

I'm using Envoy to provision a remote server. Provisioning is done by pulling the bash script from a private repo and then execute it.
The bash script ask some confirmation like yes/no (using bash "read -p"): it works as expected when i'm connected to the remote server... the script wait for user input.
Instead Envoy seems to ignore any prompt. Is it an expected behavior?
Any workaround?
Yes, this is expected. There's nothing for read to read from so it doesn't.
You have a few options.
Rewrite your script to use a config file when there's no terminal to prompt from.
Use something like [ -t 0 ] to test if the standard input is a terminal and load a configuration file with defaults. The simplest way to do that is just have a file that contains appropriate variable assignments and just source it . defaults.sh or whatever. You don't even need the -t test if you source the defaults first since then anything the user inputs will over-ride the default value.
Rewrite your script to have sane defaults.
Rewrite whatever runs the script to provide your script input via pipeline/file via redirection (e.g. printf 'answer 1\nanswer 2\n' | ./script.sh or ./script.sh <answerfile).

Resources