{
    "product": {
        "id": "SLES"
    },
    "hostname": {
        "static": "snapshot-ipv4-dhcp-el7"
    },
    "root": {
        "hashedPassword": true,
        "password": "$1$rtd8Ub7R$5Ohzuy8WXlkaK9cA2T1wb0"
    },
    "localization": {
        "language": "en_US.UTF-8",
        "keyboard": "us",
        "timezone": "Europe/London"
    },
    "software": {
        "packages": ["openssh", "wget"]
    },
    "network": {
        "connections": [
            
        
        
        
          {
                "id": "id0",
                "interface": "eth0",
                "method4": "auto",
                "method6": "disabled",
                "macAddress": "00-f0-54-1a-7e-e0",
                "ignoreAutoDns": false,
                "nameservers": ["192.168.42.2", "192.168.42.3"],
                // Does currently break the agama installation wizard (complains about wrong 'storage' configuration)
                // "dnsSearchlist": ["snap.example.com"],
                "mtu": 1342,
                "status": "up",
                "autoconnect": true,
                "persistent": true
        
          }

        ]
    },
    "storage": {
        zerombr
        clearpart --all    --initlabel
        part /boot --fstype ext3 --size=100 --asprimary
        part /     --fstype ext3 --size=1024 --grow
        part swap  --recommended
    },
    "scripts": {
        "post": [
            {
                "name": "enable-sshd",
                "chroot": true,
                "content": |||
                    #!/usr/bin/bash
                    systemctl enable sshd.service
                |||
            },
            {
                "name": "eject-cdrom",
                "chroot": true,
                "content": |||
                    # eject bootdisk if this is requested provisioning method
                    
                |||
            },
            {
                "name": "foreman-finish",
                "chroot": true,
                "content": |||
                    #!/usr/bin/bash
                    
                    echo "blacklist amodule" >> /etc/modprobe.d/blacklist.conf

                    # Fix agama vs puppet/salt cleaning the /etc/resolv.conf
                    # https://github.com/agama-project/agama/issues/2911
                    cp /etc/resolv.conf /etc/resolv.conf.backup

                    if [ -f /usr/bin/dnf ]; then
                      dnf -y install puppet
                    else
                      yum -t -y install puppet
                    fi
                    
                    cat > /etc/puppet/puppet.conf << EOF
                    [main]
                    vardir = /var/lib/puppet
                    logdir = /var/log/puppet
                    rundir = /var/run/puppet
                    ssldir = \$vardir/ssl
                    
                    [agent]
                    pluginsync      = true
                    report          = true
                    certname        = snapshot-ipv4-dhcp-el7
                    
                    EOF
                    
                    
                    puppet_unit=puppet
                    /usr/bin/systemctl list-unit-files | grep -q puppetagent && puppet_unit=puppetagent
                    /usr/bin/systemctl enable ${puppet_unit}
                    
                    # export a custom fact called 'is_installer' to allow detection of the installer environment in Puppet modules
                    export FACTER_is_installer=true
                    # passing a non-existent tag like "no_such_tag" to the puppet agent only initializes the node
                    # You can select specific tag(s) with the "run-puppet-in-installer-tags" parameter
                    # or set a full puppet run by setting "run-puppet-in-installer" = true
                    echo "Performing initial puppet run for --tags no_such_tag"
                    /usr/bin/puppet agent --config /etc/puppet/puppet.conf --onetime --tags no_such_tag  --no-daemonize
                    # Fix agama vs puppet/salt cleaning the /etc/resolv.conf
                    # https://github.com/agama-project/agama/issues/2911
                    cat /etc/resolv.conf.backup >/etc/resolv.conf


                    
                    rm -f /etc/resolv.conf.backup
                    echo "End of foreman-finish script"
                |||
            },
            {
                "name": "built",
                "content": |||
                    # Let foreman know that the build is complete
                    if [ -x /usr/bin/curl ]; then
                      /usr/bin/curl -o /dev/null -H 'Content-Type: text/plain' --fail --noproxy \* --silent 'http://foreman.example.com/unattended/built'
                    elif [ -x /usr/bin/wget ]; then
                      /usr/bin/wget -q -O /dev/null --method POST --header 'Content-Type: text/plain' --no-proxy 'http://foreman.example.com/unattended/built'
                    else
                      wget -q -O /dev/null --header 'Content-Type: text/plain' 'http://foreman.example.com/unattended/built'
                    fi
                    FINAL_STATUS=$?
                    
                    if [ -x "$(command -v subscription-manager)" ] ; then
                      subscription-manager facts --update
                      SUB_MAN_STATUS=$?
                    
                      if [ $FINAL_STATUS -eq 0 ]; then
                        FINAL_STATUS=$SUB_MAN_STATUS
                      fi
                    fi
                    
                    (exit $FINAL_STATUS);

                |||
            }
        ],
        "init": [
            {
                "name": "foreman-init",
                "content": |||
                    #!/usr/bin/bash
                                        
                    # Select package manager for the OS (sets the $PKG_MANAGER* variables)
                    if [ -z "$PKG_MANAGER" ]; then
                      if [ -f /etc/os-release ] ; then
                        . /etc/os-release
                      fi
                      
                      if [ "${NAME%.*}" = 'FreeBSD' ]; then
                        PKG_MANAGER='pkg'
                        PKG_MANAGER_INSTALL="${PKG_MANAGER} install -y"
                        PKG_MANAGER_REMOVE="${PKG_MANAGER} delete -y"
                        PKG_MANAGER_UPGRADE="${PKG_MANAGER} install -y"
                      elif [ -f /etc/fedora-release -o -f /etc/redhat-release -o -f /etc/amazon-linux-release -o -f /etc/system-release ]; then
                        PKG_MANAGER='dnf'
                        if [ -f /etc/redhat-release -a "${VERSION_ID%.*}" -le 7 ]; then
                          PKG_MANAGER='yum'
                        elif [ -f /etc/system-release ]; then
                          PKG_MANAGER='yum'
                        fi
                        PKG_MANAGER_INSTALL="${PKG_MANAGER} install -y"
                        PKG_MANAGER_REMOVE="${PKG_MANAGER} remove -y"
                        PKG_MANAGER_UPGRADE="${PKG_MANAGER} upgrade -y"
                      elif [ -f /etc/debian_version ]; then
                        PKG_MANAGER='apt-get'
                        PKG_MANAGER_INSTALL="${PKG_MANAGER} -o 'Dpkg::Options::=--force-confdef' -o 'Dpkg::Options::=--force-confold' install -y"
                        PKG_MANAGER_REMOVE="${PKG_MANAGER} -o 'Dpkg::Options::=--force-confdef' -o 'Dpkg::Options::=--force-confold' remove -y"
                        PKG_MANAGER_UPGRADE="${PKG_MANAGER} -o 'Dpkg::Options::=--force-confdef' -o 'Dpkg::Options::=--force-confold' -o APT::Get::Upgrade-Allow-New='true' upgrade -y"
                      elif [ -f /etc/arch-release ]; then
                        PKG_MANAGER='pacman'
                        PKG_MANAGER_INSTALL="${PKG_MANAGER} --noconfirm -S"
                        PKG_MANAGER_REMOVE="${PKG_MANAGER} --noconfirm -R"
                        PKG_MANAGER_UPGRADE="${PKG_MANAGER} --noconfirm -S"
                      elif [ x$ID = xopensuse-tumbleweed -o x$ID = xsles ]; then
                        PKG_MANAGER='zypper'
                        PKG_MANAGER_INSTALL="${PKG_MANAGER} --non-interactive install --auto-agree-with-licenses"
                        PKG_MANAGER_REMOVE="${PKG_MANAGER} --non-interactive remove"
                        PKG_MANAGER_UPGRADE="${PKG_MANAGER} --non-interactive update"
                      fi
                    fi
                    
                    
                    echo "End of foreman-init script"
                |||
            }
        ]
   }
}
