#python #linux and check (and delete if existing) a user

import pwd
 
def check_user_and_delete(user):
    try:
        if pwd.getpwnam(user) is True:
            res = sudo("userdel {}".format(user))
        if res.return_code == 0:
            print "== > User {} deleted".format(user)
        else:
            print "== > User {} not deleted".format(user)
    except KeyError:
            pass

Such an annoying noise

Sep 24 11:55:57 mail postfix/smtps/smtpd[22346]: Anonymous TLS connection established from unknown[178.162.195.12]: TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)
Sep 24 11:56:02 mail postfix/smtps/smtpd[22346]: NOQUEUE: filter: RCPT from unknown[178.162.195.12]: <test@mail.lucafrancesca.me>: Sender address triggers FILTER smtp-amavis:[::1]:10026; from=<test@mail.lucafrancesca.me> to=<test@gmail.com> proto=SMTP helo=<win-f09mvh2gdn6.domain>
Sep 24 11:56:02 mail postfix/smtps/smtpd[22346]: NOQUEUE: filter: RCPT from unknown[178.162.195.12]: <test@mail.lucafrancesca.me>: Sender address triggers FILTER smtp-amavis:[::1]:10024; from=<test@mail.lucafrancesca.me> to=<test@gmail.com> proto=SMTP helo=<win-f09mvh2gdn6.domain>
Sep 24 11:56:02 mail postfix/smtps/smtpd[22346]: NOQUEUE: reject: RCPT from unknown[178.162.195.12]: 554 5.7.1 <test@gmail.com>: Recipient address rejected: Access denied; from=<test@mail.lucafrancesca.me> to=<test@gmail.com> proto=SMTP helo=<win-f09mvh2gdn6.domain>
Sep 24 11:56:04 mail postfix/smtps/smtpd[22346]: lost connection after RCPT from unknown[178.162.195.12]

And a huge amount of

Sep 24 14:17:41 mail postfix/smtps/smtpd[30237]: warning: unknown[178.162.195.12]: SASL LOGIN authentication failed: authentication failure x
Sep 24 14:17:41 mail postfix/smtps/smtpd[30237]: lost connection after AUTH from unknown[178.162.195.12] x
Sep 24 14:17:41 mail postfix/smtps/smtpd[30237]: disconnect from unknown[178.162.195.12] x
Sep 24 14:17:41 mail postfix/smtps/smtpd[30237]: connect from unknown[178.162.195.12] x
Sep 24 14:17:42 mail postfix/smtps/smtpd[30237]: Anonymous TLS connection established from unknown[178.162.195.12]: TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits) x
Sep 24 14:22:43 mail postfix/smtps/smtpd[30237]: timeout after EHLO from unknown[178.162.195.12]

But with the beauty which is iptables

iptables -A INPUT -s 178.162.195.12 -j DROP

A little better on the mail server and the peace is reached.

How Spotify is ahead of the pack in using containers

Gigaom

In late December, CoreOS CEO and container guru Alex Polvi proclaimed in a tweet that he believes 2015 will be the year of the production-ready container, which would be a testament to how fast companies are adopting the technology that promises more portability and less overhead than virtual machines.

For music streaming service Spotify, however, containers are already a way of life. The streaming-music provider has been using containers in production on a large scale, according to Mats Linander, Spotify’s infrastructure team lead.

This is a big deal given that it seems only a few companies beyond cloud providers like Google or Joyent have gone public with how they are using container technology in production. Indeed, when Ben Golub, CEO of the container-management startup Docker, came on the Structure Show podcast in December and described…

View original post 1,534 more words

#Jenkins and #fabric script to execute commands remotely

tee /tmp/fabfile.py <<EOF
from fabric.api import *
import wget

env.hosts     = open('hostfile', 'r').readlines()
env.user      = open('userfile', 'r').readline().strip()
env.password  = open('passwordfile', 'r').readline().strip()


def vm_run_cmd(cmd, priv=True):
    if priv is True:
        sudo(cmd)
    else:
        run(cmd)


def vm_exec_remote_script(uri, privt=False):
        temp_f = wget.download(uri)
        inf = open(temp_f)
        vm_run_cmd(inf.read().replace('\n', ' '), privt)
        inf.close()
EOF

tee /tmp/hostfile <<EOF
localhost
EOF

tee /tmp/userfile <<EOF
xxxxxx
EOF

tee /tmp/passwordfile <<EOF
xxxxxx
EOF

cd /tmp/
virtualenv venv
source venv/bin/activate
fab vm_exec_remote_script:'https://raw.githubusercontent.com/Flukas88/CodeUtils/master/hello.bash',privt=$sa
fab vm_run_cmd:"$cmdline",priv=$sa
deactivate

#Packer and #VirtualBox for #Vagrant: the easy life

{
    "variables": {
        "ssh_name": "test",
        "ssh_pass": "test",
        "hostname": "testbox"
    },

    "builders": [{
        "type": "virtualbox-iso",
        "guest_os_type": "Ubuntu_64",

        "vboxmanage": [
            ["modifyvm", "{{.Name}}", "--vram", "32"], 
        ],

        "disk_size" : 15000,

        "iso_url": "",
        "iso_checksum": "",
        "iso_checksum_type": "md5",

        "ssh_username": "{{user `ssh_name`}}",
        "ssh_password": "{{user `ssh_pass`}}",
        "ssh_wait_timeout": "20m",

        "shutdown_command": "echo {{user `ssh_pass`}} | sudo -S shutdown -P now",

        "boot_command" : [
            "<esc><esc><enter><wait>",
            "/install/vmlinuz noapic ",
            "preseed/url=https://raw.githubusercontent.com/Flukas88/CodeUtils/master/preseed.cfg ",
            "debian-installer=en_US auto locale=en_US kbd-chooser/method=us ",
            "hostname={{user `hostname`}} ",
            "fb=false debconf/frontend=noninteractive ",
            "keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA ",
            "keyboard-configuration/variant=USA console-setup/ask_detect=false ",
            "initrd=/install/initrd.gz -- <enter>"
        ]
    }]
 ,
  "post-processors": [
    "vagrant"
]
}