Wednesday, August 17, 2016

Ansible : Galaxy

http://docs.ansible.com/ansible/galaxy.html

Advanced Control over Role Requirements Files

For more advanced control over where to download roles from, including support for remote repositories, Ansible 1.8 and later support a new YAML format for the role requirements file, which must end in a ‘yml’ extension. It works like this:
ansible-galaxy install -r requirements.yml
The extension is important. If the .yml extension is left off, the ansible-galaxy CLI will assume the file is in the “basic” format and will be confused.
And here’s an example showing some specific version downloads from multiple sources. In one of the examples we also override the name of the role and download it as something different:
 # from galaxy
 - src: yatesr.timezone

 # from GitHub
 - src: https://github.com/bennojoy/nginx

 # from GitHub, overriding the name and specifying a specific tag
 - src: https://github.com/bennojoy/nginx
   version: master
   name: nginx_role

 # from a webserver, where the role is packaged in a tar.gz
 - src: https://some.webserver.example.com/files/master.tar.gz
   name: http-role

 # from Bitbucket
 - src: git+http://bitbucket.org/willthames/git-ansible-galaxy
   version: v1.4

 # from Bitbucket, alternative syntax and caveats
 - src: http://bitbucket.org/willthames/hg-ansible-galaxy
   scm: hg

# from GitLab or other git-based scm
 - src: git@gitlab.company.com:mygroup/ansible-base.git
   scm: git
   version: 0.1.0
As you can see in the above, there are a large amount of controls available to customize where roles can be pulled from, and what to save roles as.
You can also pull down multiple roles from a single source (just make sure that you have a meta/main.yml file at the root level).
meta\main.yml
common-role1\tasks\main.yml
common-role2\tasks\main.yml
For example, if the above common roles are published to a git repo, you can pull them down using:
# multiple roles from the same repo
- src: git@gitlab.company.com:mygroup/ansible-common.git
  name: common-roles
  scm: git
  version: master
You could then use these common roles in your plays
---
- hosts: webservers
  roles:
    - common-roles/common-role1
    - common-roles/common-role2
Roles pulled from galaxy work as with other SCM sourced roles above.
Example:
ansible-galaxy install -r requirements.yml -p /tmp
(requirements.yml contains role specification , version : is the version tag in source control , name: is the role name)

Linux : Snapshot

Create snapshot

lvcreate -s -n snaplvol1 -l 100 vg0/vol1
100 means extents, usually 4M per extents

Then you make system changes.

If changes go well:
Remove snapshot

lvremove -f vg0/snaplvol1

If changes do not go well:
Rollback to snapshot (abort change)

lvconvert --merge vg0/snaplvol1

If this volume is in use, it will be merged during next reboot.


Cancel Snapshot Merge
If at this point, you don't want to rollback to previous snapshot after the next reboot:

Before reboot:

grep description /etc/lvm/archive/vg0*.vg

Find the file with the following output

description = "Created *before* executing 'lvconvert --merge vg0/snaplvol1'"

Then run vgcfgrestore with this file

vgcfgrestore --file /etc/lvm/archive/vg0xxxxxxx.vg

Then reboot

Thursday, August 11, 2016

Linux : force the Linux kernel to crash

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s2-kdump-configuration-testing.html

force the Linux kernel to crash:

echo 1 > /proc/sys/kernel/sysrq
echo c > /proc/sysrq-trigger