The following script implies that your Jenkins has Nested View Plugin installed. Without it, our task is can be solved as easy as that:
jnk = jenkins.model.Jenkins.instance
jnk.views.findAll {
jnk.getItem(OUR_JOB_NAME) in it.items
}
The following script implies that your Jenkins has Nested View Plugin installed. Without it, our task is can be solved as easy as that:
jnk = jenkins.model.Jenkins.instance
jnk.views.findAll {
jnk.getItem(OUR_JOB_NAME) in it.items
}
myView = hudson.model.Hudson.instance.getView('My Favorite View') | |
// let's add a job by its name | |
myView.doAddJobToView('aGoodJob') | |
// and remove another | |
myView.doRemoveJobFromView('aBadJob') |
hudson.model.Hudson.items.findAll { | |
it.name =~ /SOME_REGEXP/ | |
}.each { | |
it.renameTo(it.name + '.old') | |
} |
In case you want to run ansible
(or ansible-playbook
) command against a set of hosts that makes sense only for one run,
you can don't bother to create one-time inventory file, but simply define a comma-separated list of hosts as argument of --invertory
option (or its short form that's simply -i
) as follows:
ansible --inventory=myhost1,myhost2,myhost3 all -m setup -a 'filter=*name*'
(note that all
in this command line stands for the target hostname)
If you have only one host to run your playbook against, your inventory string must ends with ,
In some environments, users used for applications deployment are restricted from creating intercative sessions.
By default, in a session opened by Ansible SSH_TTY
environment variable is set, so this session can seems interactive.
A found workaround is to turn on Pipelinig mode in Ansible configuration:
[ssh_connection]
pipelining = True
As a free benefit, your tasks in such kind of configuration would run a bit faster.
ansible-playbook --connection=local 127.0.0.1 playbook.yml
127.0.0.1 ansible_connection=local
#!/bin/bash | |
ANSIBLE_ROOT=${ANSIBLE_ROOT:-/opt/ansible} | |
DISTR_ROOT=${DISTR_ROOT:-/vagrant} | |
yum install -y python-setuptools python-devel libffi-devel openssl-devel | |
easy_install virtualenv | |
virtualenv "$ANSIBLE_ROOT" | |
. "$ANSIBLE_ROOT/bin/activate" | |
# PY_LIBS can contain a space-separated list of Python libraries your playbooks require to run (e.g., "dnspython shade") |
This style of coding should look familiar for the old Unix programmers, because it uses C-like functions from os module:
import os
pid = os.fork()
if pid:
# in a parent process - write the child's pid
The following minimalistic Vagrantfile
sets up a CentOS 7 virtual machine, installs Docker on it, pulls Busybox image and starts a container running Nginx:
Vagrant.configure(2) do |config|
config.vm.box = 'centos/7'
config.vm.provision 'docker' do |d|
d.pull_images 'busybox'
d.run 'nginx'
end
end
The best-documented (and maybe simply the best) way of running Ansible commands against a set of target hosts is by using hosts' groups in inventory file. For example:
[git]
git-au-node1.example.com
git-au-node2.example.com
git-au-node3.example.com
git-us-node1.example.com