Package: scm-config
SCMSelf Managed Configuration Management(SCM) is a simple command line app for configuration management, written in python.Designed to run only on ubuntu operating systemThis tool, currently supports below resourcesservicedirectoryfilefirewallA resource definition in scm is directly related to the action of standard linux commands, example. service, directories, files.pre-requisites install python 3.6 & above environment on the machineInstallationsudoapt-getupdate
sudoapt-getinstallpython3.8python3-pip-y
mkdir-p/root/scmcd/root/scm
pip3installscm-config
scm-vUsageUsage:scm[OPTIONS]COMMAND[ARGS]...

Options:-v,--versionDisplay''stheapplicationversion--install-completion[bash|zsh|fish|powershell|pwsh]Installcompletionforthespecifiedshell.--show-completion[bash|zsh|fish|powershell|pwsh]Showcompletionforthespecifiedshell,tocopyitorcustomizetheinstallation.--helpShowthismessageandexit.

Commands:creatediffinfoinitpushremovevalidatescm creates two directories in the root directory during the "init" command, for example "/root/scm", one is for storing the receipe configuration and other one is for maintaining the configuration in the hash format, this mechanism provides the scm to run any number of times without worrying about the failures.Example workflow for Apache+PHP configuration(After the installation)scm initscm create --receipe "apache"Copy the contents from theapache.tomlto root/scm/config/apache.tomlscm validate --receipe "apache"scm diff --receipe "apache"scm push --receipe "apache"Commands overviewcommandcommand descriptionusageExampleinitUsed for initialization, creates necessary files and directories for the tool to store configuration.scm initcreateCreates the receipe .toml file in the config directory based on the receipe namescm create --receipescm create --receipe apachevalidateValidates the receipe file configuration based on the standard defined resourcesscm validate --receipescm validate --receipe apacheinfoLists the configurations that are defined in the receipe filescm info --receipescm info --receipe apachediffLists the differences between the existing and the current configuration, if this is this is new receipe, outputs all the configurationsscm diff --receipescm diff --receipe apachepushPushes the configuration defined in the receipe file to the operating system and stores the configuration in config_hash_directoryscm push --receipescm push --receipe apacheremoveRemoves the configuration from the hash directory and also removes the receipe file from the config directoryscm push --receipe  [optional --force [optional --clean-filesscm remove --receipe apache --force --clean-filesResource Detailed informationServiceService resource is useful for installing and managing packages from the linux repository,Note that currently this tool is designed to support only on Ubuntu Operating System*Name parameter in the below section is a list format, meaning it can take multiple values and the actions and other parameters are applied to each name resource accordinglyExample[service.setup]
name = ["apache2"] 
action= ["install", "enable"]In the above example, "service" is the resource and "setup" is the service identifier.name  -> Name of the service that is to be installed on the ubuntu systemaction -> Action to be done on the listed service, currently these are only supported["install", "enable", "disable"][service.ops]
name = ["apache2"]
action =["restart"]In the above example, "service" is the resource and "ops" is the service identifier. once the service is installed and service operations can be done using this tool.name  -> Name of the service that is to be installed on the ubuntu systemaction -> Action to be done on the listed service, currently these are only supported["stop", "start", "restart", "reload", "disable", "enable"]DirectoryDirectory resource is useful for installing and managing the metadata directories on the system,Note that currently this resource is tested only on Ubuntu Operating System, but can run on any Linux Operating SystemExample# Modify the directory permissions 
[directory.list]
name = ["/etc/apache"] 
params = {'owner'='root','group'='root','mode'= '0755'}
action = ['create']
notifies = "@format {this.service.ops}"In the above example, "directory" is the resource and "list" is the service identifier.name  -> Name of the directory where the metadata needs modification including creation of the directory using the action methodparams -> parameter to support the directory operations, currently ['owner', 'group' and 'mode'] are supported in the listaction -> Action to be done on the listed service, currently for directories only ['create'] is supportednotifies -> Parameter to notify any other resource in the same recipe file, In example, notifies the service ops resources, that would restart the apache2 service based on the modifications["install", "enable", "disable"]FileFile resource is useful for managing the metadata and the content on the linux file system,Note that currently this resource is tested only on Ubuntu Operating System, but can run on any Linux Operating SystemExample# Modify the input content of the file 
[file.conf]
name = ["/var/www/customers/public_html/index.php"]
action = ["create"]
override ="true"
content  = ["This is the test file"]
params = {'owner'= 'root','group'= 'root','mode' = '0755'}
notifies = "@format {this.service.ops}"In the above example, "file" is the resource and "conf" is the service identifier.name  -> Name of the file where the content need to be added or appended based on the configuration requirementaction -> Action to be done on the listed service, currently for file only ['create'] is supportedoverride -> This parameter will override if there is any existing file, default it will append the content to the filecontent -> Input content for the file provide in the form the double quotes. For simplicity ,large content is not tested with the current version of the code.params -> parameter to support the file operations, currently ['owner', 'group' and 'mode'] are supported in the listnotifies -> Parameter to notify any other resource in the same recipe file, In example, notifies the service ops resources, that would restart the apache2 service based on the modifications["install", "enable", "disable"]FirewallFirewall resource is useful for managing firewall rules using UFW linux command,Note that currently this resource is tested only on Ubuntu Operating System, but can run on any Linux Operating SystemExample# Modify the input content of the file 
[firewall.setup]
name = ["Apache"]
action=["allow"]In the above example, "firewall" is the resource and "setup" is the service identifier.name  -> Name of the resource where need to allow firewall trafficaction -> Action to be done on the listed service, currently for file only ['allow'] is supported["allow"]Complete overview of the example file# Service setup for the apache instance[service.setup]name=["apache2"]action=["install","enable"]# Service restart for the apache instance[service.ops]name=["apache2"]action=["restart"][firewall.setup]name=["Apache"]action=["allow"]# Modify the directory permissions[directory.list]name=["/etc/apache"]params={'owner'='root','group'='root','mode'='0755'}action=['create']notifies="@format {this.service.ops}"# Modify the input content of the file[file.conf]name=["/var/www/customers/public_html/index.php"]action=["create"]content=["This is the test file"]params={'owner'='root','group'='root','mode'='0755'}notifies="@format {this.service.ops}"Installation and UsageManual clone$gitclonehttps://github.com/Sai-Repalle/scm_project$cdscm_project$python3-mvenvvenv$sourcevenv/bin/activate$pipinstall-rrequirements.txtinitializationinit command is used for initialization and helpful to create the respective directories, also this command is useful for expanding future versions of the scm toolinitInitialize the tool without any parameters, this would set the configuration files required for tool to work$scminitoutputscminit[INFO][04-22-202206:08:13]::ReadingtheJsonconfiguration/root/scm/scm/settings/settings.json[INFO][04-22-202206:08:13]::creatingdirectoryCONFIG_DIR[INFO][04-22-202206:08:13]::creatingdirectoryCONFIG_HASH_DIR[INFO][04-22-202206:08:13]::creatingfilesCONFIG_DEF_FILE[INFO][04-22-202206:08:13]::creatingfilesCONFIG_HASH_FILEcreatecreate <name>$scmcreate--receipe<receipe>Below example, will create a receipe called "apache" andapache.tomlfile is created in the config directory located at the root directory of the scmoutputscmcreate--receipeapache[INFO][04-22-202206:09:56]::ReadingtheJsonconfiguration/root/scm/scm/settings/settings.json[INFO][04-22-202206:09:56]::creatingdirectoryCONFIG_DIR[INFO][04-22-202206:09:56]::CONFIG_DIRdirectoryalreadyexists[INFO][04-22-202206:09:56]::creatingdirectoryCONFIG_HASH_DIR[INFO][04-22-202206:09:56]::CONFIG_HASH_DIRdirectoryalreadyexists[INFO][04-22-202206:09:56]::creatingfilesCONFIG_DEF_FILE[INFO][04-22-202206:09:56]::creatingfilesCONFIG_HASH_FILinfoinfo --receipe <name>$scminfo--receipe<receipe>Below example, info command is listing all the resources and its actions based on the configuration defined in the receipe file.outputscminfo--receipeapache[INFO][04-25-202202:00:37]::ReadingtheJsonconfiguration/root/scm/settings.json[INFO][04-25-202202:00:37]::creatingdirectoryCONFIG_DIR[INFO][04-25-202202:00:37]::CONFIG_DIRdirectoryalreadyexists[INFO][04-25-202202:00:37]::creatingdirectoryCONFIG_HASH_DIR[INFO][04-25-202202:00:37]::CONFIG_HASH_DIRdirectoryalreadyexists[INFO][04-25-202202:00:37]::creatingfilesCONFIG_DEF_FILE[INFO][04-25-202202:00:37]::creatingfilesCONFIG_HASH_FILE[INFO][04-25-202202:00:37]::SERVICE.setup-{'name':['apache2'],'action':['install','enable','start']}[INFO][04-25-202202:00:37]::SERVICE.ops-{'name':['apache2'],'action':['restart']}[INFO][04-25-202202:00:37]::SERVICE.setup_php-{'name':['php','libapache2-mod-php'],'action':['install']}[INFO][04-25-202202:00:37]::FIREWALL.setup-{'name':['Apache'],'action':['allow']}[INFO][04-25-202202:00:37]::FILE.conf-{'name':['/var/www/html/index.php'],'action':['create'],'override':'true','content':['<?php\n header("Content-Type: text/plain");\n echo "Hello, world!\n";\n'],'params':{'owner':'root','group':'root','mode':'0755'},'notifies':"{'name': ['apache2'], 'action': ['restart']}"}[INFO][04-25-202202:00:37]::FILE.phpindex-{'name':['/etc/apache2/mods-enabled/dir.conf'],'action':['create'],'override':'true','content':['<IfModule mod_dir.c>\n DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm </IfModule>'],'params':{'owner':'root','group':'root','mode':'0755'},'notifies':"{'name': ['apache2'], 'action': ['restart']}"}validatevalidate -receipe <name>$scmvalidate--receipe<receipe>Below example, validate command is validating all the resources and its actions based on the configuration defined in the receipe file, If all the resources and its configurations are in valid state, receipe would output to do next step, if there are any issues, please refere to the documentation.outputscmvalidate--receipeapache[INFO][04-25-202202:01:47]::ReadingtheJsonconfiguration/root/scm/settings.json[INFO][04-25-202202:01:47]::creatingdirectoryCONFIG_DIR[INFO][04-25-202202:01:47]::CONFIG_DIRdirectoryalreadyexists[INFO][04-25-202202:01:47]::creatingdirectoryCONFIG_HASH_DIR[INFO][04-25-202202:01:47]::CONFIG_HASH_DIRdirectoryalreadyexists[INFO][04-25-202202:01:47]::creatingfilesCONFIG_DEF_FILE[INFO][04-25-202202:01:47]::creatingfilesCONFIG_HASH_FILE[INFO][04-25-202202:01:47]::apachereceipefileisvalidforpush,use`scmdiff`todifferenceswiththeexistingconfigurationdiffdiff -receipe <name>$scmdiff--receipe<receipe>In the below example, if the confiugration in the receipe file is already appplied, scm would output that the configuration is update to date with the existing configuration[INFO][04-25-202202:05:00]::ReadingtheJsonconfiguration/root/scm/settings.json[INFO][04-25-202202:05:00]::ReadingtheJsonconfiguration/root/scm/settings.json[INFO][04-25-202202:05:00]::creatingdirectoryCONFIG_DIR[INFO][04-25-202202:05:00]::CONFIG_DIRdirectoryalreadyexists[INFO][04-25-202202:05:00]::creatingdirectoryCONFIG_HASH_DIR[INFO][04-25-202202:05:00]::CONFIG_HASH_DIRdirectoryalreadyexists[INFO][04-25-202202:05:00]::creatingfilesCONFIG_DEF_FILE[INFO][04-25-202202:05:00]::creatingfilesCONFIG_HASH_FILE[INFO][04-25-202202:05:00]::apachereceipefileisvalidforpush,use`scmdiff`todifferenceswiththeexistingconfiguration[INFO][04-25-202202:05:00]::ReadingtheJsonconfigurationconfig_hash/hash_config_md5.json[INFO][04-25-202202:05:00]::`apache`configurationisupdatetodatewiththeexistingconfigurationIn the below example, if the configuration in the receipe file is pushed to the operating system to install the required servicesroot@ip-172-31-255-140:~/scm/config#scmdiff--receipeapache_remove[INFO][04-25-202202:20:37]::ReadingtheJsonconfiguration/root/scm/config/settings.json[INFO][04-25-202202:20:37]::ReadingtheJsonconfiguration/root/scm/config/settings.json[INFO][04-25-202202:20:37]::creatingdirectoryCONFIG_DIR[INFO][04-25-202202:20:37]::CONFIG_DIRdirectoryalreadyexists[INFO][04-25-202202:20:37]::creatingdirectoryCONFIG_HASH_DIR[INFO][04-25-202202:20:37]::CONFIG_HASH_DIRdirectoryalreadyexists[INFO][04-25-202202:20:37]::creatingfilesCONFIG_DEF_FILE[INFO][04-25-202202:20:37]::CONFIG_DEF_FILEfilealreadyexists[INFO][04-25-202202:20:37]::creatingfilesCONFIG_HASH_FILE[INFO][04-25-202202:20:37]::apache_removereceipefileisvalidforpush,use`scmdiff`todifferenceswiththeexistingconfiguration[INFO][04-25-202202:20:37]::ReadingtheJsonconfigurationconfig_hash/hash_config_md5.json[INFO][04-25-202202:20:37]::Followingresourceswillbeapplied:[INFO][04-25-202202:20:37]::SERVICE.setup:['systemctl stop apache2','systemctl disable apache2','sudo apt-get update -y','sudo apt-get remove apache2 -y'][INFO][04-25-202202:20:37]::Followingresourceswillbeapplied:[INFO][04-25-202202:20:37]::SERVICE.setup_php:['sudo apt-get update -y','sudo apt-get remove php -y','sudo apt-get update -y','sudo apt-get remove libapache2-mod-php -y']pushpush -receipe <name>$scmpush--receipe<receipe>In the below example, scm push is pushing hte receipe named "apache_remove" and the subsequent commands are being run on the operating to the remove the servicesoutputroot@ip-172-31-255-140:~/scm/config#scmpush--receipeapache_remove[INFO][04-25-202202:21:34]::ReadingtheJsonconfiguration/root/scm/config/settings.json[INFO][04-25-202202:21:34]::ReadingtheJsonconfiguration/root/scm/config/settings.json[INFO][04-25-202202:21:34]::creatingdirectoryCONFIG_DIR[INFO][04-25-202202:21:34]::CONFIG_DIRdirectoryalreadyexists[INFO][04-25-202202:21:34]::creatingdirectoryCONFIG_HASH_DIR[INFO][04-25-202202:21:34]::CONFIG_HASH_DIRdirectoryalreadyexists[INFO][04-25-202202:21:34]::creatingfilesCONFIG_DEF_FILE[INFO][04-25-202202:21:34]::CONFIG_DEF_FILEfilealreadyexists[INFO][04-25-202202:21:34]::creatingfilesCONFIG_HASH_FILE[INFO][04-25-202202:21:34]::apache_removereceipefileisvalidforpush,use`scmdiff`todifferenceswiththeexistingconfiguration[INFO][04-25-202202:21:34]::ReadingtheJsonconfigurationconfig_hash/hash_config_md5.json[INFO][04-25-202202:21:34]::ReadingtheJsonconfiguration/root/scm/config/settings.json[INFO][04-25-202202:21:34]::Followingresourceswillbeapplied:[INFO][04-25-202202:21:34]::SERVICE.setup:['systemctl stop apache2','systemctl disable apache2','sudo apt-get update -y','sudo apt-get remove apache2 -y'][INFO][04-25-202202:21:34]::Applyingthecommand`systemctlstopapache2`[INFO][04-25-202202:21:35]::Applyingthecommand`systemctldisableapache2`Synchronizingstateofapache2.servicewithSysVservicescriptwith/lib/systemd/systemd-sysv-install.
Executing:/lib/systemd/systemd-sysv-installdisableapache2[INFO][04-25-202202:21:35]::Applyingthecommand`sudoapt-getupdate-y`Hit:1http://us-east-1.ec2.archive.ubuntu.com/ubuntubionicInRelease
Get:2http://us-east-1.ec2.archive.ubuntu.com/ubuntubionic-updatesInRelease[88.7kB]Get:3http://us-east-1.ec2.archive.ubuntu.com/ubuntubionic-backportsInRelease[74.6kB]Get:4http://security.ubuntu.com/ubuntubionic-securityInRelease[88.7kB]Fetched252kBin0s(666kB/s)Readingpackagelists...Done[INFO][04-25-202202:21:42]::Applyingthecommand`sudoapt-getremoveapache2-y`Readingpackagelists...Done
Buildingdependencytree
Readingstateinformation...Done
Thefollowingpackageswereautomaticallyinstalledandarenolongerrequired:apache2-dataapache2-utilsssl-cert
Use'sudo apt autoremove'toremovethem.
ThefollowingpackageswillbeREMOVED:apache20upgraded,0newlyinstalled,1toremoveand2notupgraded.
Afterthisoperation,537kBdiskspacewillbefreed.(Readingdatabase...94525filesanddirectoriescurrentlyinstalled.)Removingapache2(2.4.29-1ubuntu4.22)...
Processingtriggersforman-db(2.8.3-2ubuntu0.1)...
Processingtriggersforufw(0.36-0ubuntu0.18.04.2)...
Rulesupdatedforprofile'Apache'removeremove --receipe <name> --force <optional> --clean_files <optional>$scmpush--receipe<receipe>In the below example, scm is removing theapache_removereceipe from the configuration hash directory,outputscmremove--receipeapache_remove[INFO][04-25-202202:33:38]::ReadingtheJsonconfiguration/root/scm/config/settings.json[INFO][04-25-202202:33:38]::ReadingtheJsonconfiguration/root/scm/config/settings.json[INFO][04-25-202202:33:38]::creatingdirectoryCONFIG_DIR[INFO][04-25-202202:33:38]::CONFIG_DIRdirectoryalreadyexists[INFO][04-25-202202:33:38]::creatingdirectoryCONFIG_HASH_DIR[INFO][04-25-202202:33:38]::CONFIG_HASH_DIRdirectoryalreadyexists[INFO][04-25-202202:33:38]::creatingfilesCONFIG_DEF_FILE[INFO][04-25-202202:33:38]::CONFIG_DEF_FILEfilealreadyexists[INFO][04-25-202202:33:38]::creatingfilesCONFIG_HASH_FILE[INFO][04-25-202202:33:38]::apache_removereceipefileisvalidforpush,use`scmdiff`todifferenceswiththeexistingconfiguration[INFO][04-25-202202:33:38]::Configurationdoesn'tremovethereceipefile,pleasecleanupmanually