H5L5o

          Twenty years ago and I remember like yesterday. He said,
          «Herr Breuer, why don't you try to learn what I have to teach
          rather than prove how much I don't know?»

          Irvin Yalom, When Nietzsche Wept, 2005 Ed.

Some Puppet scripting
.....................

Motivations to create and to learn Puppet scripting language are not the same. Actually, if you are capable to speak "bash" language (required for IT Unix (BSD, MacOS, iOS, Linux, Android etc.) -- it is sufficient to be familiar with File and Exec resources (Puppet terminology). Knowing puppet-script DSL (domain specific language) makes your life easier. Even better is if you are familiar with Ruby. However there are other IT-automation systems: Cfengine, Chef, Ansible, MaSSH, and more.. with each of them having it's own scripting language. You've been warned:)

Reading of excellent series of articles on IT-automation [1] is highly recommended.

Host control via SSH (bash)
...........................

  root@agent~#  sudo -u virtu -s
  virtu@agent~$ xlsfonts
  ..
  virtu@agent~$ DISPLAY=:0 xmessage -center -fg yellow -bg red \
                -fn 12x24 -title "YOU ARE HACKED" \
                "My name is bash and I rock da house" &

Facter:
.......

Facter runs on clients and collects facts that the server can use as variables

  virtu@puppet:~$ facter
  aio_agent_version => 1.10.1
  ..
  networking => {
  ..
      interfaces => {
      enp0s3 => {
  ..

Puppet Manifest
...............

Let's make some quick test first:

  root@puppet:~# cat \
      /etc/puppetlabs/code/environments/production/manifests/site.pp

  exec { 'run command':
    command => '/usr/bin/whoami > /tmp/i_am'
  }

  virtu@puppet:~$ sudo /opt/puppetlabs/bin/puppet agent --test
  virtu@puppet:~$ ls -l /tmp
  ..
  -rw-r--r-- 1 root  root      5 mai   21 11:38 i_am
  ..
  virtu@puppet:~$ cat /tmp/i_am
  root
  virtu@puppet:~$

So it's root who drives the agent via puppet.

Job
---

Write bash script to install SimulIDE (Arduino and AVR) on agent.
Put icon on "plank":

Discover /usr/share/applications. you have to drop proper .desktop file from nautilus into plank. Figure out how to do this programmatically (~/.configure/plank).

Restart "plank":

  killall plank
  plank

Tips:

  1. puppet file server should run on master (properly configured)

  2. puppet-agent operates as root user.

  3. /etc/puppet/fileserver.conf
  ..
  [files]
  path = /var/puppet/files
  allow * # ???
  ..

  4. Do not reinstall once installed.

  /etc/puppet/manifests/site.pp
  ..
  file { "/home/virtu/bashinstallscript.sh":
    source => "puppet://bashinstallscript.sh",
    mode => 644,
  }

  exec { 'runbashinstallscript':
    ensure => "present",
    command => '/bin/sh /home/virtu/bashinstallscript.sh'
  }
  ..

  5. $ sudo -s
     # whoami
     root

     # sudo -u virtu bash -c 'whoami && whoami'
     virtu
     virtu

Links
-----

1. Getting Started with Configuration Management.
   An Introduction to Configuration Management.
   Configuration Management 101: Writing Ansible Playbooks.
   Configuration Management 101: Writing Puppet Manifests.
   Configuration Management 101: Writing Chef Recipes.

   https://www.digitalocean.com/community/tutorials
        /configuration-management-101-writing-puppet-manifests

2. Puppet 4.10 reference manual
   https://docs.puppet.com/puppet/4.10/

3. Puppet Tutorial By Alessandro Franceschi

     http://www.example42.com/tutorials/PuppetTutorial/#slide-20

4. Хакер 2011.05. Master of puppets: Установка и настройка системы..

     https://xakep.ru/2011/05/14/55238/

5. Massive SSH

     http://m.a.tt/er/massh/
     http://m.a.tt/er/massh.tgz

6. Run a program requiring xserver as another user
   by passing on the xauth cookie

     https://gist.github.com/lentschi/605b031ea32d7c5c0655b5008ed8ee2a

7. Re: Questions about xmessage and resources files

      http://unix.derkeiler.com/Newsgroups/comp.unix.programmer
           /2009-03/msg00329.html

8. Howto specify X scalable fonts from the command line

     https://tronche.com/wiki
           /Howto_specify_X_scalable_fonts_from_the_command_line

