К основному контенту

Сообщения

Ansible - Appending to lists and dictionaries  n this blog post I'll show how to add items to lists and dictionaries, when using loops, and across tasks. Normally when trying to add a new item to the variable, while in the loop, or between tasks, Ansible will ovewrite the values, keeping the result of the last iteration. For example, let's see what will be the result of running the following playbook: --- - name: Append to list hosts: localhost vars: cisco: - CiscoRouter01 - CiscoRouter02 - CiscoRouter03 - CiscoSwitch01 arista: - AristaSwitch01 - AristaSwitch02 - AristaSwitch03 tasks: - name: Add Cisco and Airsta devices to the list set_fact: devices: "{{ item }}" with_items: - "{{ cisco }}" - "{{ arista }}" - name: Debug list debug: var: devices verbosity: 0 [przemek@quasar blog]$ ansible-playbook append_list.yml PLAY [Append to list] ****************...
Недавние сообщения
How to set host_key_checking=false in ansible inventory file?   Due to the fact that I answered this in 2014, I have updated my answer to account for more recent versions of ansible. Yes, you can do it at the host/inventory level (Which became possible on newer ansible versions ) or global level: inventory : Add the following. ansible_ssh_common_args='-o StrictHostKeyChecking=no' host : Add the following. ansible_ssh_extra_args='-o StrictHostKeyChecking=no' hosts/inventory options will work with connection type ssh and not paramiko . Some people may strongly argue that inventory and hosts is more secure because the scope is more limited. global: Ansible User Guide - Host Key Checking You can do it either in the /etc/ansible/ansible.cfg or ~/.ansible.cfg file: [defaults] host_key_checking = False Or you can setup and env variable (this might not work on newer ansible versions): export ANSIBLE_HOST_KEY_CHECKING=False          ...
bash-completion   Installation The easiest way to install this software is to use a package; refer to Repology for a comprehensive list of operating system distributions, package names, and available versions. Depending on the package, you may still need to source it from either /etc/bashrc or ~/.bashrc (or any other file sourcing those). You can do this by simply using: # Use bash-completion, if available [[ $PS1 && -f /usr/share/bash-completion/bash_completion ]] && \ . /usr/share/bash-completion/bash_completion (if you happen to have only bash >= 4.1 installed, see further if not) If you don't have the package readily available for your distribution, or you simply don't want to use one, you can install bash completion using the standard commands for GNU autotools packages: autoreconf -i # if not installing from prepared release tarball ./configure make make check # optional, requires python3 with pytest >= 3.6 and p...
Use physical harddisk in Virtual Box     I made a smug comment ("Straight forward") when this question was originally posted and found myself at this page some months later looking for the same answer Straight forward instructions Today, I managed to boot from physical drives. This achievement required; 60 min straight forward reading 30 min writing this 20 min trying different options in VirtualBox Dear reader , your attention is directed at the fact that it is equally straight forward to kill your data when the disc is accessed in this manner. The procedure on how to accomplish this is left as an exercise... Pics (it did happen :) 1. Create vmdk drives that read from real drives To create an image that represents an entire physical hard disk (which will not contain any actual data, as this will all be stored on the physical disk), on a Linux host, use the command VBoxManage internalcommands createrawvmdk \ -filename /path/to/f...
Give a specific user permissions to a device without giving access to other users   There are multiple ways of accomplishing this. 1. Add your user to the group that owns the device Generally in most distros, block devices are owned by a specific group. All you need to do is add your user to that group. For example, on my system: # ls -l /dev/sdb brw-rw---- 1 root disk 8, 16 2014/07/07-21:32:25 /dev/sdb Thus I need to add my user to the disk group. # usermod -a -G disk patrick 2. Change the permissions of the device The idea is to create a udev rule to run a command when the device is detected. First you need to find a way to identify the device. You use udevadm for this. For example: # udevadm info -a -n /dev/sdb Udevadm info starts with the device specified by the devpath and then walks up the chain of parent devices. It prints for every device found, all possible attributes in the udev rules key format. A rule to match, can be composed by the ...

Force SSH client to use password authentication instead of public key

To test if you can connect to a host using password authentication and explicitly deny public key authentication: ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no user@host This also works for Secure Copy: scp -o PreferredAuthentications=password -o PubkeyAuthentication=no local.file user@host:/path/to/remote.file use old ssh ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no -o HostKeyAlgorithms=+ssh-dss user@host

How to do Arithmetic Operations in Ansible

You can use arithmetic calculations in Ansible using the Jinja syntax. This is helpful in many situations where you have stored the output of an operation, and you need to manipulate that value. All usual operation like addition, subtraction, multiplication, division, and modulo are possible. Let us start with an example. We will be using the  debug module  to print the out the result. The following tasks show all the basic arithmetic operations. The output is given in comments. Ansible arithmetic operation example - hosts: loc tasks: - debug: msg: "addition{{ 4 +3 }}" #Ansible addition 7 - debug: msg: "substraction {{ 4 - 3 }}" #Ansible arithmetic substraction 1 - debug: msg: "multiplication {{ 4 * 3 }}" #multiplication 12 - debug: msg: "Modulo operation {{ 7 % 4}}" #ansible Modulo operation - find remainder 3 - debug: msg: "floating division {{ 4 / 3}}" #ansible floating divisio...

Promoting a Standby to the Main server

Except for an absolute calamity, there is no reason to promote the hot standby to be the main server. If you need to, the general recovery steps are outlined below. There is only ONE command to do at the backup server to make it the primary server (see bottom half of page). Shut down, turn off, unplug and/or remove the main server from the network so that it is no longer active On the backup server, create the failover trigger file using the primary failover methodology (described in detail below): sudo touch /tmp/pg_failover_trigger The hot standby is now your main server. You may need to change the pg_hba.conf file as required to allow workstations to access the database. It is probably okay because it was originally copied from the main server at time of making the standby. You will only need to change the pg_hba.conf file if you added more sub-nets to the main server. Do all the work necessary to get Theatre Manager clients to point to a new database serve...

LXD - Заметки

lxd-fix-privileged   lxc config set u3 security.privileged true Allow LXD/LXC to mount Glusterfs from the host Type the following command on your host: $ sudo -i Type the following two command: # echo Y > /sys/module/fuse/parameters/userns_mounts # echo Y > /sys/module/ext4/parameters/userns_mounts Edit the /etc/rc.local file: # vi /etc/rc.local Edit/Update it as follow before exit 0 line:   echo Y > /sys/module/fuse/parameters/userns_mounts echo Y > /sys/module/ext4/parameters/userns_mounts   Mount Glusterfs client on lxc/lxd VM You need to create a mount point using the mkdir command: $ sudo mkdir /data/ Mount it as follows: $ sudo mount -t glusterfs gfs01:/gvol0 /data/ Update /etc/fstab as follows: $ echo 'gfs01:/gvol0 /data glusterfs defaults,_netdev 0 0' >> /etc/fstab Save and close the file. You can now store data at /data/ location and it will get replicated across the cl...