golden hour
/opt/saltstack/salt/lib/python3.10/site-packages/salt/states
⬆️ Go Up
Upload
File/Folder
Size
Actions
__init__.py
25 B
Del
OK
__pycache__
-
Del
OK
acme.py
5.08 KB
Del
OK
alias.py
2.49 KB
Del
OK
alternatives.py
6.75 KB
Del
OK
ansiblegate.py
7.93 KB
Del
OK
apache.py
3.95 KB
Del
OK
apache_conf.py
2.72 KB
Del
OK
apache_module.py
2.73 KB
Del
OK
apache_site.py
2.66 KB
Del
OK
aptpkg.py
1.42 KB
Del
OK
archive.py
68.24 KB
Del
OK
artifactory.py
6.84 KB
Del
OK
at.py
7.48 KB
Del
OK
augeas.py
10.57 KB
Del
OK
aws_sqs.py
2.59 KB
Del
OK
azurearm_compute.py
11.78 KB
Del
OK
azurearm_dns.py
26.05 KB
Del
OK
azurearm_network.py
89.12 KB
Del
OK
azurearm_resource.py
28.23 KB
Del
OK
beacon.py
7.58 KB
Del
OK
bigip.py
96.63 KB
Del
OK
blockdev.py
5.13 KB
Del
OK
boto3_elasticache.py
48.01 KB
Del
OK
boto3_elasticsearch.py
32.58 KB
Del
OK
boto3_route53.py
37.54 KB
Del
OK
boto3_sns.py
12.69 KB
Del
OK
boto_apigateway.py
82.83 KB
Del
OK
boto_asg.py
31.93 KB
Del
OK
boto_cfn.py
11.53 KB
Del
OK
boto_cloudfront.py
6.01 KB
Del
OK
boto_cloudtrail.py
13.18 KB
Del
OK
boto_cloudwatch_alarm.py
6.4 KB
Del
OK
boto_cloudwatch_event.py
12.33 KB
Del
OK
boto_cognitoidentity.py
13.69 KB
Del
OK
boto_datapipeline.py
18.5 KB
Del
OK
boto_dynamodb.py
29.32 KB
Del
OK
boto_ec2.py
71.98 KB
Del
OK
boto_elasticache.py
16.75 KB
Del
OK
boto_elasticsearch_domain.py
12.27 KB
Del
OK
boto_elb.py
55.1 KB
Del
OK
boto_elbv2.py
12.19 KB
Del
OK
boto_iam.py
69.16 KB
Del
OK
boto_iam_role.py
27.12 KB
Del
OK
boto_iot.py
25.33 KB
Del
OK
boto_kinesis.py
16.69 KB
Del
OK
boto_kms.py
12.11 KB
Del
OK
boto_lambda.py
35.52 KB
Del
OK
boto_lc.py
11.04 KB
Del
OK
boto_rds.py
26 KB
Del
OK
boto_route53.py
19.49 KB
Del
OK
boto_s3.py
9.32 KB
Del
OK
boto_s3_bucket.py
24.67 KB
Del
OK
boto_secgroup.py
32.62 KB
Del
OK
boto_sns.py
8.92 KB
Del
OK
boto_sqs.py
7.97 KB
Del
OK
boto_vpc.py
62.23 KB
Del
OK
bower.py
8.26 KB
Del
OK
btrfs.py
10.34 KB
Del
OK
cabal.py
5.73 KB
Del
OK
ceph.py
1.9 KB
Del
OK
chef.py
3.76 KB
Del
OK
chocolatey.py
16.15 KB
Del
OK
chronos_job.py
4.6 KB
Del
OK
cimc.py
14.32 KB
Del
OK
cisconso.py
3.14 KB
Del
OK
cloud.py
14.4 KB
Del
OK
cmd.py
40.92 KB
Del
OK
composer.py
8.38 KB
Del
OK
consul.py
5.4 KB
Del
OK
cron.py
23.39 KB
Del
OK
cryptdev.py
6.17 KB
Del
OK
csf.py
9.98 KB
Del
OK
cyg.py
7.05 KB
Del
OK
ddns.py
4.2 KB
Del
OK
debconfmod.py
6.33 KB
Del
OK
dellchassis.py
24.49 KB
Del
OK
disk.py
6.49 KB
Del
OK
docker_container.py
85.27 KB
Del
OK
docker_image.py
16.7 KB
Del
OK
docker_network.py
36.78 KB
Del
OK
docker_volume.py
6.72 KB
Del
OK
drac.py
4.17 KB
Del
OK
dvs.py
26.29 KB
Del
OK
elasticsearch.py
20.38 KB
Del
OK
elasticsearch_index.py
3.25 KB
Del
OK
elasticsearch_index_template.py
3.67 KB
Del
OK
environ.py
5.81 KB
Del
OK
eselect.py
2.27 KB
Del
OK
esxcluster.py
22.4 KB
Del
OK
esxdatacenter.py
4.44 KB
Del
OK
esxi.py
63.07 KB
Del
OK
esxvm.py
20.11 KB
Del
OK
etcd_mod.py
11 KB
Del
OK
ethtool.py
9.88 KB
Del
OK
event.py
2.48 KB
Del
OK
file.py
316.7 KB
Del
OK
firewall.py
1.33 KB
Del
OK
firewalld.py
26.08 KB
Del
OK
gem.py
7.13 KB
Del
OK
git.py
123.85 KB
Del
OK
github.py
27.25 KB
Del
OK
glance_image.py
2.26 KB
Del
OK
glassfish.py
21.47 KB
Del
OK
glusterfs.py
12.21 KB
Del
OK
gnomedesktop.py
7.47 KB
Del
OK
gpg.py
5.28 KB
Del
OK
grafana.py
12.11 KB
Del
OK
grafana4_dashboard.py
17.31 KB
Del
OK
grafana4_datasource.py
6.15 KB
Del
OK
grafana4_org.py
7.73 KB
Del
OK
grafana4_user.py
5.52 KB
Del
OK
grafana_dashboard.py
17.74 KB
Del
OK
grafana_datasource.py
5.31 KB
Del
OK
grains.py
15.57 KB
Del
OK
group.py
9.84 KB
Del
OK
heat.py
9.69 KB
Del
OK
helm.py
10.39 KB
Del
OK
hg.py
6.33 KB
Del
OK
highstate_doc.py
1.41 KB
Del
OK
host.py
8.64 KB
Del
OK
http.py
7.46 KB
Del
OK
icinga2.py
9.07 KB
Del
OK
idem.py
3.91 KB
Del
OK
ifttt.py
2.12 KB
Del
OK
incron.py
5.71 KB
Del
OK
influxdb08_database.py
2.85 KB
Del
OK
influxdb08_user.py
3.39 KB
Del
OK
influxdb_continuous_query.py
2.83 KB
Del
OK
influxdb_database.py
2.11 KB
Del
OK
influxdb_retention_policy.py
4.82 KB
Del
OK
influxdb_user.py
4.84 KB
Del
OK
infoblox_a.py
4.24 KB
Del
OK
infoblox_cname.py
4.19 KB
Del
OK
infoblox_host_record.py
6.59 KB
Del
OK
infoblox_range.py
6.85 KB
Del
OK
ini_manage.py
12.67 KB
Del
OK
ipmi.py
8.42 KB
Del
OK
ipset.py
9.66 KB
Del
OK
iptables.py
27.65 KB
Del
OK
jboss7.py
23.95 KB
Del
OK
jenkins.py
3.36 KB
Del
OK
junos.py
17.78 KB
Del
OK
kapacitor.py
6.46 KB
Del
OK
kernelpkg.py
6.42 KB
Del
OK
keyboard.py
2.01 KB
Del
OK
keystone.py
27.12 KB
Del
OK
keystone_domain.py
2.81 KB
Del
OK
keystone_endpoint.py
4.69 KB
Del
OK
keystone_group.py
3.25 KB
Del
OK
keystone_project.py
3.36 KB
Del
OK
keystone_role.py
2.33 KB
Del
OK
keystone_role_grant.py
4.08 KB
Del
OK
keystone_service.py
2.89 KB
Del
OK
keystone_user.py
3.47 KB
Del
OK
keystore.py
5.67 KB
Del
OK
kmod.py
8.59 KB
Del
OK
kubernetes.py
24.87 KB
Del
OK
layman.py
2.44 KB
Del
OK
ldap.py
19.78 KB
Del
OK
libcloud_dns.py
5.7 KB
Del
OK
libcloud_loadbalancer.py
5.66 KB
Del
OK
libcloud_storage.py
5.13 KB
Del
OK
linux_acl.py
24.42 KB
Del
OK
locale.py
2.52 KB
Del
OK
logadm.py
4.67 KB
Del
OK
logrotate.py
3.86 KB
Del
OK
loop.py
7.74 KB
Del
OK
lvm.py
13.33 KB
Del
OK
lvs_server.py
6.28 KB
Del
OK
lvs_service.py
4.38 KB
Del
OK
lxc.py
22.17 KB
Del
OK
lxd.py
7.88 KB
Del
OK
lxd_container.py
22.25 KB
Del
OK
lxd_image.py
10.59 KB
Del
OK
lxd_profile.py
7.11 KB
Del
OK
mac_assistive.py
1.55 KB
Del
OK
mac_keychain.py
5.59 KB
Del
OK
mac_xattr.py
3.15 KB
Del
OK
macdefaults.py
2.65 KB
Del
OK
macpackage.py
6.76 KB
Del
OK
makeconf.py
6.87 KB
Del
OK
marathon_app.py
4.45 KB
Del
OK
mdadm_raid.py
6.41 KB
Del
OK
memcached.py
3.95 KB
Del
OK
modjk.py
2.84 KB
Del
OK
modjk_worker.py
6.49 KB
Del
OK
module.py
18.64 KB
Del
OK
mongodb_database.py
1.65 KB
Del
OK
mongodb_user.py
6.26 KB
Del
OK
monit.py
2.68 KB
Del
OK
mount.py
50.32 KB
Del
OK
mssql_database.py
3 KB
Del
OK
mssql_login.py
3.64 KB
Del
OK
mssql_role.py
2.37 KB
Del
OK
mssql_user.py
3.51 KB
Del
OK
msteams.py
2.53 KB
Del
OK
mysql_database.py
6.05 KB
Del
OK
mysql_grants.py
8.49 KB
Del
OK
mysql_query.py
13.07 KB
Del
OK
mysql_user.py
9.51 KB
Del
OK
net_napalm_yang.py
9.15 KB
Del
OK
netacl.py
31.92 KB
Del
OK
netconfig.py
33.42 KB
Del
OK
netntp.py
12.51 KB
Del
OK
netsnmp.py
11.33 KB
Del
OK
netusers.py
16.1 KB
Del
OK
network.py
23.97 KB
Del
OK
neutron_network.py
3.96 KB
Del
OK
neutron_secgroup.py
4 KB
Del
OK
neutron_secgroup_rule.py
4.75 KB
Del
OK
neutron_subnet.py
4.29 KB
Del
OK
nexus.py
4.97 KB
Del
OK
nfs_export.py
4.92 KB
Del
OK
nftables.py
19.5 KB
Del
OK
npm.py
11.21 KB
Del
OK
ntp.py
2.12 KB
Del
OK
nxos.py
10.37 KB
Del
OK
nxos_upgrade.py
3.5 KB
Del
OK
openstack_config.py
3.26 KB
Del
OK
openvswitch_bridge.py
4.36 KB
Del
OK
openvswitch_db.py
2.24 KB
Del
OK
openvswitch_port.py
17.24 KB
Del
OK
opsgenie.py
4.07 KB
Del
OK
pagerduty.py
1.89 KB
Del
OK
pagerduty_escalation_policy.py
5.42 KB
Del
OK
pagerduty_schedule.py
6.09 KB
Del
OK
pagerduty_service.py
3.93 KB
Del
OK
pagerduty_user.py
1.18 KB
Del
OK
panos.py
48.13 KB
Del
OK
pbm.py
20.46 KB
Del
OK
pcs.py
36.46 KB
Del
OK
pdbedit.py
3.43 KB
Del
OK
pecl.py
3.65 KB
Del
OK
pip_state.py
38.55 KB
Del
OK
pkg.py
138.08 KB
Del
OK
pkgbuild.py
11.37 KB
Del
OK
pkgng.py
685 B
Del
OK
pkgrepo.py
27.53 KB
Del
OK
portage_config.py
5.01 KB
Del
OK
ports.py
5.65 KB
Del
OK
postgres_cluster.py
4.19 KB
Del
OK
postgres_database.py
6.08 KB
Del
OK
postgres_extension.py
5.68 KB
Del
OK
postgres_group.py
8.52 KB
Del
OK
postgres_initdb.py
2.84 KB
Del
OK
postgres_language.py
3.94 KB
Del
OK
postgres_privileges.py
7.86 KB
Del
OK
postgres_schema.py
4.34 KB
Del
OK
postgres_tablespace.py
6.62 KB
Del
OK
postgres_user.py
9.49 KB
Del
OK
powerpath.py
2.34 KB
Del
OK
probes.py
15.06 KB
Del
OK
process.py
1.32 KB
Del
OK
proxy.py
4.94 KB
Del
OK
pushover.py
3.13 KB
Del
OK
pyenv.py
6.07 KB
Del
OK
pyrax_queues.py
2.97 KB
Del
OK
quota.py
1.4 KB
Del
OK
rabbitmq_cluster.py
1.84 KB
Del
OK
rabbitmq_plugin.py
2.77 KB
Del
OK
rabbitmq_policy.py
4.59 KB
Del
OK
rabbitmq_upstream.py
7.9 KB
Del
OK
rabbitmq_user.py
8.89 KB
Del
OK
rabbitmq_vhost.py
3.04 KB
Del
OK
rbac_solaris.py
6.67 KB
Del
OK
rbenv.py
7.36 KB
Del
OK
rdp.py
1.28 KB
Del
OK
redismod.py
4.76 KB
Del
OK
reg.py
19.22 KB
Del
OK
restconf.py
6.41 KB
Del
OK
rsync.py
4.45 KB
Del
OK
rvm.py
6.56 KB
Del
OK
salt_proxy.py
1.34 KB
Del
OK
saltmod.py
33.12 KB
Del
OK
saltutil.py
8.91 KB
Del
OK
schedule.py
12.47 KB
Del
OK
selinux.py
18.61 KB
Del
OK
serverdensity_device.py
6.41 KB
Del
OK
service.py
37.89 KB
Del
OK
slack.py
4.98 KB
Del
OK
smartos.py
44.83 KB
Del
OK
smtp.py
2.3 KB
Del
OK
snapper.py
7.24 KB
Del
OK
solrcloud.py
4.48 KB
Del
OK
splunk.py
4.32 KB
Del
OK
splunk_search.py
3.17 KB
Del
OK
sqlite3.py
14.7 KB
Del
OK
ssh_auth.py
19.57 KB
Del
OK
ssh_known_hosts.py
7.92 KB
Del
OK
stateconf.py
494 B
Del
OK
status.py
2.21 KB
Del
OK
statuspage.py
17.29 KB
Del
OK
supervisord.py
10.48 KB
Del
OK
svn.py
8.14 KB
Del
OK
sysctl.py
4.11 KB
Del
OK
sysfs.py
2.13 KB
Del
OK
syslog_ng.py
2.97 KB
Del
OK
sysrc.py
2.82 KB
Del
OK
telemetry_alert.py
7.04 KB
Del
OK
test.py
13.09 KB
Del
OK
testinframod.py
1.35 KB
Del
OK
timezone.py
3.42 KB
Del
OK
tls.py
1.81 KB
Del
OK
tomcat.py
9.72 KB
Del
OK
trafficserver.py
8.82 KB
Del
OK
tuned.py
3.32 KB
Del
OK
uptime.py
1.87 KB
Del
OK
user.py
38.63 KB
Del
OK
vagrant.py
11.4 KB
Del
OK
vault.py
3.28 KB
Del
OK
vbox_guest.py
4.05 KB
Del
OK
victorops.py
3.32 KB
Del
OK
virt.py
80.41 KB
Del
OK
virtualenv_mod.py
11.21 KB
Del
OK
webutil.py
3.89 KB
Del
OK
win_certutil.py
4.8 KB
Del
OK
win_dacl.py
7.96 KB
Del
OK
win_dism.py
14.97 KB
Del
OK
win_dns_client.py
8.32 KB
Del
OK
win_firewall.py
6.87 KB
Del
OK
win_iis.py
31.56 KB
Del
OK
win_lgpo.py
24.99 KB
Del
OK
win_lgpo_reg.py
10.96 KB
Del
OK
win_license.py
1.6 KB
Del
OK
win_network.py
14.18 KB
Del
OK
win_path.py
6.39 KB
Del
OK
win_pki.py
5.56 KB
Del
OK
win_powercfg.py
3.79 KB
Del
OK
win_servermanager.py
10.4 KB
Del
OK
win_shortcut.py
7.81 KB
Del
OK
win_smtp_server.py
10.01 KB
Del
OK
win_snmp.py
6.64 KB
Del
OK
win_system.py
13.78 KB
Del
OK
win_wua.py
16.27 KB
Del
OK
win_wusa.py
3.53 KB
Del
OK
winrepo.py
2.74 KB
Del
OK
wordpress.py
4.82 KB
Del
OK
x509.py
27.86 KB
Del
OK
x509_v2.py
64.78 KB
Del
OK
xml.py
1.75 KB
Del
OK
xmpp.py
2.61 KB
Del
OK
zabbix_action.py
9.35 KB
Del
OK
zabbix_host.py
27.25 KB
Del
OK
zabbix_hostgroup.py
5.64 KB
Del
OK
zabbix_mediatype.py
16.89 KB
Del
OK
zabbix_template.py
35.14 KB
Del
OK
zabbix_user.py
17.6 KB
Del
OK
zabbix_usergroup.py
9.64 KB
Del
OK
zabbix_usermacro.py
9.69 KB
Del
OK
zabbix_valuemap.py
8.11 KB
Del
OK
zcbuildout.py
5.16 KB
Del
OK
zenoss.py
2.89 KB
Del
OK
zfs.py
34.48 KB
Del
OK
zk_concurrency.py
5.81 KB
Del
OK
zone.py
46.48 KB
Del
OK
zookeeper.py
11.55 KB
Del
OK
zpool.py
13.4 KB
Del
OK
Edit: cron.py
""" Management of cron, the Unix command scheduler ============================================== Cron declarations require a number of parameters. The following are the parameters used by Salt to define the various timing values for a cron job: * ``minute`` * ``hour`` * ``daymonth`` * ``month`` * ``dayweek`` (0 to 6 are Sunday through Saturday, 7 can also be used for Sunday) .. warning:: Any timing arguments not specified take a value of ``*``. This means that setting ``hour`` to ``5``, while not defining the ``minute`` param, will result in Salt adding a job that will execute every minute between 5 and 6 A.M.! Additionally, the default user for these states is ``root``. Therefore, if the cron job is for another user, it is necessary to specify that user with the ``user`` parameter. A long time ago (before 2014.2), when making changes to an existing cron job, the name declaration is the parameter used to uniquely identify the job, so if an existing cron that looks like this: .. code-block:: yaml date > /tmp/crontest: cron.present: - user: root - minute: 5 Is changed to this: .. code-block:: yaml date > /tmp/crontest: cron.present: - user: root - minute: 7 - hour: 2 Then the existing cron will be updated, but if the cron command is changed, then a new cron job will be added to the user's crontab. The current behavior is still relying on that mechanism, but you can also specify an identifier to identify your crontabs: .. code-block:: yaml date > /tmp/crontest: cron.present: - identifier: SUPERCRON - user: root - minute: 7 - hour: 2 .. versionadded:: 2014.1.2 And, some months later, you modify it: .. code-block:: yaml superscript > /tmp/crontest: cron.present: - identifier: SUPERCRON - user: root - minute: 3 - hour: 4 .. versionadded:: 2014.1.2 The old **date > /tmp/crontest** will be replaced by **superscript > /tmp/crontest**. Additionally, Salt also supports running a cron every ``x minutes`` very similarly to the Unix convention of using ``*/5`` to have a job run every five minutes. In Salt, this looks like: .. code-block:: yaml date > /tmp/crontest: cron.present: - user: root - minute: '*/5' The job will now run every 5 minutes. Additionally, the temporal parameters (minute, hour, etc.) can be randomized by using ``random`` instead of using a specific value. For example, by using the ``random`` keyword in the ``minute`` parameter of a cron state, the same cron job can be pushed to hundreds or thousands of hosts, and they would each use a randomly-generated minute. This can be helpful when the cron job accesses a network resource, and it is not desirable for all hosts to run the job concurrently. .. code-block:: yaml /path/to/cron/script: cron.present: - user: root - minute: random - hour: 2 .. versionadded:: 0.16.0 Since Salt assumes a value of ``*`` for unspecified temporal parameters, adding a parameter to the state and setting it to ``random`` will change that value from ``*`` to a randomized numeric value. However, if that field in the cron entry on the minion already contains a numeric value, then using the ``random`` keyword will not modify it. Added the opportunity to set a job with a special keyword like '@reboot' or '@hourly'. Quotes must be used, otherwise PyYAML will strip the '@' sign. .. code-block:: yaml /path/to/cron/script: cron.present: - user: root - special: '@hourly' The script will be executed every reboot if cron daemon support this option. .. code-block:: yaml /path/to/cron/otherscript: cron.absent: - user: root - special: '@daily' This counter part definition will ensure than a job with a special keyword is not set. """ import os import salt.utils.files from salt.modules.cron import _cron_matched, _needs_change def __virtual__(): if "cron.list_tab" in __salt__: return True return (False, "cron module could not be loaded") def _check_cron( user, cmd, minute=None, hour=None, daymonth=None, month=None, dayweek=None, comment=None, commented=None, identifier=None, special=None, ): """ Return the changes """ if minute is not None: minute = str(minute).lower() if hour is not None: hour = str(hour).lower() if daymonth is not None: daymonth = str(daymonth).lower() if month is not None: month = str(month).lower() if dayweek is not None: dayweek = str(dayweek).lower() if identifier is not None: identifier = str(identifier) if commented is not None: commented = commented is True if cmd is not None: cmd = str(cmd) lst = __salt__["cron.list_tab"](user) if special is None: for cron in lst["crons"]: if _cron_matched(cron, cmd, identifier): if any( [ _needs_change(x, y) for x, y in ( (cron["minute"], minute), (cron["hour"], hour), (cron["daymonth"], daymonth), (cron["month"], month), (cron["dayweek"], dayweek), (cron["identifier"], identifier), (cron["cmd"], cmd), (cron["comment"], comment), (cron["commented"], commented), ) ] ): return "update" return "present" else: for cron in lst["special"]: if _cron_matched(cron, cmd, identifier): if any( [ _needs_change(x, y) for x, y in ( (cron["spec"], special), (cron["identifier"], identifier), (cron["cmd"], cmd), (cron["comment"], comment), (cron["commented"], commented), ) ] ): return "update" return "present" return "absent" def _check_cron_env(user, name, value=None): """ Return the environment changes """ if value is None: value = "" # Matching value set in salt.modules.cron._render_tab lst = __salt__["cron.list_tab"](user) for env in lst["env"]: if name == env["name"]: if value != env["value"]: return "update" return "present" return "absent" def _get_cron_info(): """ Returns the proper group owner and path to the cron directory """ owner = "root" if __grains__["os"] == "FreeBSD": group = "wheel" crontab_dir = "/var/cron/tabs" elif __grains__["os"] == "OpenBSD": group = "crontab" crontab_dir = "/var/cron/tabs" elif __grains__["os_family"] == "Solaris": group = "root" crontab_dir = "/var/spool/cron/crontabs" elif __grains__["os"] == "MacOS": group = "wheel" crontab_dir = "/usr/lib/cron/tabs" else: group = "root" crontab_dir = "/var/spool/cron" return owner, group, crontab_dir def present( name, user="root", minute="*", hour="*", daymonth="*", month="*", dayweek="*", comment=None, commented=False, identifier=False, special=None, ): """ Verifies that the specified cron job is present for the specified user. It is recommended to use `identifier`. Otherwise the cron job is installed twice if you change the name. For more advanced information about what exactly can be set in the cron timing parameters, check your cron system's documentation. Most Unix-like systems' cron documentation can be found via the crontab man page: ``man 5 crontab``. name The command that should be executed by the cron job. user The name of the user whose crontab needs to be modified, defaults to the root user minute The information to be set into the minute section, this can be any string supported by your cron system's the minute field. Default is ``*`` hour The information to be set in the hour section. Default is ``*`` daymonth The information to be set in the day of month section. Default is ``*`` month The information to be set in the month section. Default is ``*`` dayweek The information to be set in the day of week section. Default is ``*`` comment User comment to be added on line previous the cron job commented The cron job is set commented (prefixed with ``#DISABLED#``). Defaults to False. .. versionadded:: 2016.3.0 identifier Custom-defined identifier for tracking the cron line for future crontab edits. This defaults to the state name special A special keyword to specify periodicity (eg. @reboot, @hourly...). Quotes must be used, otherwise PyYAML will strip the '@' sign. .. versionadded:: 2016.3.0 """ name = name.strip() if identifier is False: identifier = name ret = {"changes": {}, "comment": "", "name": name, "result": True} if __opts__["test"]: status = _check_cron( user, cmd=name, minute=minute, hour=hour, daymonth=daymonth, month=month, dayweek=dayweek, comment=comment, commented=commented, identifier=identifier, special=special, ) ret["result"] = None if status == "absent": ret["comment"] = "Cron {} is set to be added".format(name) elif status == "present": ret["result"] = True ret["comment"] = "Cron {} already present".format(name) elif status == "update": ret["comment"] = "Cron {} is set to be updated".format(name) return ret if special is None: data = __salt__["cron.set_job"]( user=user, minute=minute, hour=hour, daymonth=daymonth, month=month, dayweek=dayweek, cmd=name, comment=comment, commented=commented, identifier=identifier, ) else: data = __salt__["cron.set_special"]( user=user, special=special, cmd=name, comment=comment, commented=commented, identifier=identifier, ) if data == "present": ret["comment"] = "Cron {} already present".format(name) return ret if data == "new": ret["comment"] = "Cron {} added to {}'s crontab".format(name, user) ret["changes"] = {user: name} return ret if data == "updated": ret["comment"] = "Cron {} updated".format(name) ret["changes"] = {user: name} return ret ret["comment"] = "Cron {} for user {} failed to commit with error \n{}".format( name, user, data ) ret["result"] = False return ret def absent(name, user="root", identifier=False, special=None, **kwargs): """ Verifies that the specified cron job is absent for the specified user. If an ``identifier`` is not passed then the ``name`` is used to identify the cron job for removal. name The command that should be absent in the user crontab. user The name of the user whose crontab needs to be modified, defaults to the root user identifier Custom-defined identifier for tracking the cron line for future crontab edits. This defaults to the state name special The special keyword used in the job (eg. @reboot, @hourly...). Quotes must be used, otherwise PyYAML will strip the '@' sign. """ # NOTE: The keyword arguments in **kwargs are ignored in this state, but # cannot be removed from the function definition, otherwise the use # of unsupported arguments will result in a traceback. name = name.strip() if identifier is False: identifier = name ret = {"name": name, "result": True, "changes": {}, "comment": ""} if __opts__["test"]: status = _check_cron(user, name, identifier=identifier) ret["result"] = None if status == "absent": ret["result"] = True ret["comment"] = "Cron {} is absent".format(name) elif status == "present" or status == "update": ret["comment"] = "Cron {} is set to be removed".format(name) return ret if special is None: data = __salt__["cron.rm_job"](user, name, identifier=identifier) else: data = __salt__["cron.rm_special"]( user, name, special=special, identifier=identifier ) if data == "absent": ret["comment"] = "Cron {} already absent".format(name) return ret if data == "removed": ret["comment"] = "Cron {} removed from {}'s crontab".format(name, user) ret["changes"] = {user: name} return ret ret["comment"] = "Cron {} for user {} failed to commit with error {}".format( name, user, data ) ret["result"] = False return ret def file( name, source_hash="", source_hash_name=None, user="root", template=None, context=None, replace=True, defaults=None, backup="", **kwargs ): """ Provides file.managed-like functionality (templating, etc.) for a pre-made crontab file, to be assigned to a given user. name The source file to be used as the crontab. This source file can be hosted on either the salt master server, or on an HTTP or FTP server. For files hosted on the salt file server, if the file is located on the master in the directory named spam, and is called eggs, the source string is ``salt://spam/eggs`` If the file is hosted on a HTTP or FTP server then the source_hash argument is also required source_hash This can be either a file which contains a source hash string for the source, or a source hash string. The source hash string is the hash algorithm followed by the hash of the file: ``md5=e138491e9d5b97023cea823fe17bac22`` source_hash_name When ``source_hash`` refers to a hash file, Salt will try to find the correct hash by matching the filename/URI associated with that hash. By default, Salt will look for the filename being managed. When managing a file at path ``/tmp/foo.txt``, then the following line in a hash file would match: .. code-block:: text acbd18db4cc2f85cedef654fccc4a4d8 foo.txt However, sometimes a hash file will include multiple similar paths: .. code-block:: text 37b51d194a7513e45b56f6524f2d51f2 ./dir1/foo.txt acbd18db4cc2f85cedef654fccc4a4d8 ./dir2/foo.txt 73feffa4b7f6bb68e44cf984c85f6e88 ./dir3/foo.txt In cases like this, Salt may match the incorrect hash. This argument can be used to tell Salt which filename to match, to ensure that the correct hash is identified. For example: .. code-block:: yaml foo_crontab: cron.file: - name: https://mydomain.tld/dir2/foo.txt - source_hash: https://mydomain.tld/hashes - source_hash_name: ./dir2/foo.txt .. note:: This argument must contain the full filename entry from the checksum file, as this argument is meant to disambiguate matches for multiple files that have the same basename. So, in the example above, simply using ``foo.txt`` would not match. .. versionadded:: 2016.3.5 user The user to whom the crontab should be assigned. This defaults to root. template If this setting is applied then the named templating engine will be used to render the downloaded file. Currently, jinja and mako are supported. context Overrides default context variables passed to the template. replace If the crontab should be replaced, if False then this command will be ignored if a crontab exists for the specified user. Default is True. defaults Default context passed to the template. backup Overrides the default backup mode for the user's crontab. """ # Initial set up mode = "0600" try: group = __salt__["user.info"](user)["groups"][0] except Exception: # pylint: disable=broad-except ret = { "changes": {}, "comment": "Could not identify group for user {}".format(user), "name": name, "result": False, } return ret cron_path = salt.utils.files.mkstemp() with salt.utils.files.fopen(cron_path, "w+") as fp_: raw_cron = __salt__["cron.raw_cron"](user) if not raw_cron.endswith("\n"): raw_cron = "{}\n".format(raw_cron) fp_.write(salt.utils.stringutils.to_str(raw_cron)) ret = {"changes": {}, "comment": "", "name": name, "result": True} # Avoid variable naming confusion in below module calls, since ID # declaration for this state will be a source URI. source = name if not replace and os.stat(cron_path).st_size > 0: ret["comment"] = "User {} already has a crontab. No changes made".format(user) os.unlink(cron_path) return ret if __opts__["test"]: fcm = __salt__["file.check_managed"]( name=cron_path, source=source, source_hash=source_hash, source_hash_name=source_hash_name, user=user, group=group, mode=mode, attrs=[], # no special attrs for cron template=template, context=context, defaults=defaults, saltenv=__env__, **kwargs ) ret["result"], ret["comment"] = fcm os.unlink(cron_path) return ret # If the source is a list then find which file exists source, source_hash = __salt__["file.source_list"](source, source_hash, __env__) # Gather the source file from the server try: sfn, source_sum, comment = __salt__["file.get_managed"]( name=cron_path, template=template, source=source, source_hash=source_hash, source_hash_name=source_hash_name, user=user, group=group, mode=mode, attrs=[], saltenv=__env__, context=context, defaults=defaults, skip_verify=False, # skip_verify **kwargs ) except Exception as exc: # pylint: disable=broad-except ret["result"] = False ret["changes"] = {} ret["comment"] = "Unable to manage file: {}".format(exc) return ret if comment: ret["comment"] = comment ret["result"] = False os.unlink(cron_path) return ret try: ret = __salt__["file.manage_file"]( name=cron_path, sfn=sfn, ret=ret, source=source, source_sum=source_sum, user=user, group=group, mode=mode, attrs=[], saltenv=__env__, backup=backup, ) except Exception as exc: # pylint: disable=broad-except ret["result"] = False ret["changes"] = {} ret["comment"] = "Unable to manage file: {}".format(exc) return ret cron_ret = None if "diff" in ret["changes"]: cron_ret = __salt__["cron.write_cron_file_verbose"](user, cron_path) # Check cmd return code and show success or failure if cron_ret["retcode"] == 0: ret["comment"] = "Crontab for user {} was updated".format(user) ret["result"] = True ret["changes"] = ret["changes"] else: ret["comment"] = "Unable to update user {} crontab {}. Error: {}".format( user, cron_path, cron_ret["stderr"] ) ret["result"] = False ret["changes"] = {} elif ret["result"]: ret["comment"] = "Crontab for user {} is in the correct state".format(user) ret["changes"] = {} os.unlink(cron_path) return ret def env_present(name, value=None, user="root"): """ Verifies that the specified environment variable is present in the crontab for the specified user. name The name of the environment variable to set in the user crontab user The name of the user whose crontab needs to be modified, defaults to the root user value The value to set for the given environment variable """ ret = {"changes": {}, "comment": "", "name": name, "result": True} if __opts__["test"]: status = _check_cron_env(user, name, value=value) ret["result"] = None if status == "absent": ret["comment"] = "Cron env {} is set to be added".format(name) elif status == "present": ret["result"] = True ret["comment"] = "Cron env {} already present".format(name) elif status == "update": ret["comment"] = "Cron env {} is set to be updated".format(name) return ret data = __salt__["cron.set_env"](user, name, value=value) if data == "present": ret["comment"] = "Cron env {} already present".format(name) return ret if data == "new": ret["comment"] = "Cron env {} added to {}'s crontab".format(name, user) ret["changes"] = {user: name} return ret if data == "updated": ret["comment"] = "Cron env {} updated".format(name) ret["changes"] = {user: name} return ret ret["comment"] = "Cron env {} for user {} failed to commit with error \n{}".format( name, user, data ) ret["result"] = False return ret def env_absent(name, user="root"): """ Verifies that the specified environment variable is absent from the crontab for the specified user name The name of the environment variable to remove from the user crontab user The name of the user whose crontab needs to be modified, defaults to the root user """ name = name.strip() ret = {"name": name, "result": True, "changes": {}, "comment": ""} if __opts__["test"]: status = _check_cron_env(user, name) ret["result"] = None if status == "absent": ret["result"] = True ret["comment"] = "Cron env {} is absent".format(name) elif status == "present" or status == "update": ret["comment"] = "Cron env {} is set to be removed".format(name) return ret data = __salt__["cron.rm_env"](user, name) if data == "absent": ret["comment"] = "Cron env {} already absent".format(name) return ret if data == "removed": ret["comment"] = "Cron env {} removed from {}'s crontab".format(name, user) ret["changes"] = {user: name} return ret ret["comment"] = "Cron env {} for user {} failed to commit with error {}".format( name, user, data ) ret["result"] = False return ret
Save