├── .github ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── README.md ├── cloud ├── __init__.py ├── amazon │ ├── GUIDELINES.md │ ├── __init__.py │ ├── cloudformation_facts.py │ ├── cloudtrail.py │ ├── cloudwatchevent_rule.py │ ├── dynamodb_table.py │ ├── ec2_ami_copy.py │ ├── ec2_asg_facts.py │ ├── ec2_customer_gateway.py │ ├── ec2_elb_facts.py │ ├── ec2_eni.py │ ├── ec2_eni_facts.py │ ├── ec2_group_facts.py │ ├── ec2_lc_facts.py │ ├── ec2_lc_find.py │ ├── ec2_remote_facts.py │ ├── ec2_snapshot_facts.py │ ├── ec2_vol_facts.py │ ├── ec2_vpc_dhcp_options.py │ ├── ec2_vpc_dhcp_options_facts.py │ ├── ec2_vpc_igw.py │ ├── ec2_vpc_nacl.py │ ├── ec2_vpc_nacl_facts.py │ ├── ec2_vpc_nat_gateway.py │ ├── ec2_vpc_net_facts.py │ ├── ec2_vpc_peer.py │ ├── ec2_vpc_route_table.py │ ├── ec2_vpc_route_table_facts.py │ ├── ec2_vpc_subnet.py │ ├── ec2_vpc_subnet_facts.py │ ├── ec2_vpc_vgw.py │ ├── ec2_win_password.py │ ├── ecs_cluster.py │ ├── ecs_service.py │ ├── ecs_service_facts.py │ ├── ecs_task.py │ ├── ecs_taskdefinition.py │ ├── efs.py │ ├── efs_facts.py │ ├── execute_lambda.py │ ├── iam_mfa_device_facts.py │ ├── iam_server_certificate_facts.py │ ├── kinesis_stream.py │ ├── lambda.py │ ├── lambda_alias.py │ ├── lambda_event.py │ ├── lambda_facts.py │ ├── redshift.py │ ├── redshift_subnet_group.py │ ├── route53_facts.py │ ├── route53_health_check.py │ ├── route53_zone.py │ ├── s3_bucket.py │ ├── s3_lifecycle.py │ ├── s3_logging.py │ ├── s3_website.py │ ├── sns_topic.py │ ├── sqs_queue.py │ ├── sts_assume_role.py │ └── sts_session_token.py ├── atomic │ ├── __init__.py │ ├── atomic_host.py │ └── atomic_image.py ├── azure │ ├── __init__.py │ └── azure_rm_deployment.py ├── centurylink │ ├── __init__.py │ ├── clc_aa_policy.py │ ├── clc_alert_policy.py │ ├── clc_blueprint_package.py │ ├── clc_firewall_policy.py │ ├── clc_group.py │ ├── clc_loadbalancer.py │ ├── clc_modify_server.py │ ├── clc_publicip.py │ ├── clc_server.py │ └── clc_server_snapshot.py ├── cloudstack │ ├── __init__.py │ ├── cs_account.py │ ├── cs_affinitygroup.py │ ├── cs_cluster.py │ ├── cs_configuration.py │ ├── cs_domain.py │ ├── cs_facts.py │ ├── cs_firewall.py │ ├── cs_instance.py │ ├── cs_instance_facts.py │ ├── cs_instancegroup.py │ ├── cs_ip_address.py │ ├── cs_iso.py │ ├── cs_loadbalancer_rule.py │ ├── cs_loadbalancer_rule_member.py │ ├── cs_network.py │ ├── cs_nic.py │ ├── cs_pod.py │ ├── cs_portforward.py │ ├── cs_project.py │ ├── cs_region.py │ ├── cs_resourcelimit.py │ ├── cs_router.py │ ├── cs_securitygroup.py │ ├── cs_securitygroup_rule.py │ ├── cs_snapshot_policy.py │ ├── cs_sshkeypair.py │ ├── cs_staticnat.py │ ├── cs_template.py │ ├── cs_user.py │ ├── cs_vmsnapshot.py │ ├── cs_volume.py │ ├── cs_vpc.py │ ├── cs_zone.py │ └── cs_zone_facts.py ├── google │ ├── __init__.py │ ├── gcdns_record.py │ ├── gcdns_zone.py │ ├── gce_img.py │ └── gce_tag.py ├── lxc │ ├── __init__.py │ └── lxc_container.py ├── lxd │ ├── __init__.py │ ├── lxd_container.py │ └── lxd_profile.py ├── misc │ ├── __init__.py │ ├── ovirt.py │ ├── proxmox.py │ ├── proxmox_kvm.py │ ├── proxmox_template.py │ ├── rhevm.py │ ├── virt.py │ ├── virt_net.py │ └── virt_pool.py ├── openstack │ ├── __init__.py │ ├── os_flavor_facts.py │ ├── os_group.py │ ├── os_ironic_inspect.py │ ├── os_keystone_domain.py │ ├── os_keystone_domain_facts.py │ ├── os_keystone_role.py │ ├── os_keystone_service.py │ ├── os_port_facts.py │ ├── os_project.py │ ├── os_project_facts.py │ ├── os_recordset.py │ ├── os_server_group.py │ ├── os_stack.py │ ├── os_user_facts.py │ ├── os_user_role.py │ └── os_zone.py ├── ovh │ ├── __init__.py │ └── ovh_ip_loadbalancing_backend.py ├── ovirt │ ├── __init__.py │ ├── ovirt_affinity_labels.py │ ├── ovirt_affinity_labels_facts.py │ ├── ovirt_auth.py │ ├── ovirt_clusters.py │ ├── ovirt_clusters_facts.py │ ├── ovirt_datacenters.py │ ├── ovirt_datacenters_facts.py │ ├── ovirt_disks.py │ ├── ovirt_external_providers.py │ ├── ovirt_external_providers_facts.py │ ├── ovirt_groups.py │ ├── ovirt_groups_facts.py │ ├── ovirt_host_networks.py │ ├── ovirt_host_pm.py │ ├── ovirt_hosts.py │ ├── ovirt_hosts_facts.py │ ├── ovirt_mac_pools.py │ ├── ovirt_networks.py │ ├── ovirt_networks_facts.py │ ├── ovirt_nics.py │ ├── ovirt_nics_facts.py │ ├── ovirt_permissions.py │ ├── ovirt_permissions_facts.py │ ├── ovirt_quotas.py │ ├── ovirt_quotas_facts.py │ ├── ovirt_storage_domains.py │ ├── ovirt_storage_domains_facts.py │ ├── ovirt_templates.py │ ├── ovirt_templates_facts.py │ ├── ovirt_users.py │ ├── ovirt_users_facts.py │ ├── ovirt_vmpools.py │ ├── ovirt_vmpools_facts.py │ ├── ovirt_vms.py │ └── ovirt_vms_facts.py ├── profitbricks │ ├── __init__.py │ ├── profitbricks.py │ ├── profitbricks_datacenter.py │ ├── profitbricks_nic.py │ ├── profitbricks_volume.py │ └── profitbricks_volume_attachments.py ├── rackspace │ ├── __init__.py │ ├── rax_clb_ssl.py │ ├── rax_mon_alarm.py │ ├── rax_mon_check.py │ ├── rax_mon_entity.py │ ├── rax_mon_notification.py │ └── rax_mon_notification_plan.py ├── serverless.py ├── smartos │ ├── __init__.py │ └── smartos_image_facts.py ├── softlayer │ ├── __init__.py │ └── sl_vm.py ├── vmware │ ├── __init__.py │ ├── vca_fw.py │ ├── vca_nat.py │ ├── vca_vapp.py │ ├── vmware_cluster.py │ ├── vmware_datacenter.py │ ├── vmware_dns_config.py │ ├── vmware_dvs_host.py │ ├── vmware_dvs_portgroup.py │ ├── vmware_dvswitch.py │ ├── vmware_guest.py │ ├── vmware_host.py │ ├── vmware_local_user_manager.py │ ├── vmware_maintenancemode.py │ ├── vmware_migrate_vmk.py │ ├── vmware_portgroup.py │ ├── vmware_target_canonical_facts.py │ ├── vmware_vm_facts.py │ ├── vmware_vm_shell.py │ ├── vmware_vm_vss_dvs_migrate.py │ ├── vmware_vmkernel.py │ ├── vmware_vmkernel_ip_config.py │ ├── vmware_vmotion.py │ ├── vmware_vsan_cluster.py │ ├── vmware_vswitch.py │ └── vsphere_copy.py ├── webfaction │ ├── __init__.py │ ├── webfaction_app.py │ ├── webfaction_db.py │ ├── webfaction_domain.py │ ├── webfaction_mailbox.py │ └── webfaction_site.py └── xenserver_facts.py ├── clustering ├── __init__.py ├── consul.py ├── consul_acl.py ├── consul_kv.py ├── consul_session.py ├── kubernetes.py └── znode.py ├── commands ├── __init__.py └── expect.py ├── crypto ├── __init__.py ├── openssl_privatekey.py └── openssl_publickey.py ├── database ├── __init__.py ├── influxdb │ ├── __init__.py │ ├── influxdb_database.py │ └── influxdb_retention_policy.py ├── misc │ ├── __init__.py │ ├── mongodb_parameter.py │ ├── mongodb_user.py │ ├── redis.py │ └── riak.py ├── mssql │ ├── __init__.py │ └── mssql_db.py ├── mysql │ ├── __init__.py │ └── mysql_replication.py ├── postgresql │ ├── __init__.py │ ├── postgresql_ext.py │ ├── postgresql_lang.py │ └── postgresql_schema.py └── vertica │ ├── __init__.py │ ├── vertica_configuration.py │ ├── vertica_facts.py │ ├── vertica_role.py │ ├── vertica_schema.py │ └── vertica_user.py ├── files ├── __init__.py ├── archive.py ├── blockinfile.py ├── patch.py └── tempfile.py ├── identity ├── __init__.py ├── ipa │ ├── __init__.py │ ├── ipa_group.py │ ├── ipa_hbacrule.py │ ├── ipa_host.py │ ├── ipa_hostgroup.py │ ├── ipa_role.py │ ├── ipa_sudocmd.py │ ├── ipa_sudocmdgroup.py │ ├── ipa_sudorule.py │ └── ipa_user.py └── opendj │ ├── __init__.py │ └── opendj_backendprop.py ├── infrastructure ├── __init__.py └── foreman │ ├── __init__.py │ ├── foreman.py │ └── katello.py ├── messaging ├── __init__.py ├── rabbitmq_binding.py ├── rabbitmq_exchange.py ├── rabbitmq_parameter.py ├── rabbitmq_plugin.py ├── rabbitmq_policy.py ├── rabbitmq_queue.py ├── rabbitmq_user.py └── rabbitmq_vhost.py ├── monitoring ├── __init__.py ├── airbrake_deployment.py ├── bigpanda.py ├── boundary_meter.py ├── circonus_annotation.py ├── datadog_event.py ├── datadog_monitor.py ├── honeybadger_deployment.py ├── librato_annotation.py ├── logentries.py ├── logicmonitor.py ├── logicmonitor_facts.py ├── monit.py ├── nagios.py ├── newrelic_deployment.py ├── pagerduty.py ├── pagerduty_alert.py ├── pingdom.py ├── rollbar_deployment.py ├── sensu_check.py ├── sensu_subscription.py ├── stackdriver.py ├── statusio_maintenance.py ├── uptimerobot.py ├── zabbix_group.py ├── zabbix_host.py ├── zabbix_hostmacro.py ├── zabbix_maintenance.py └── zabbix_screen.py ├── network ├── __init__.py ├── a10 │ ├── __init__.py │ ├── a10_server.py │ ├── a10_server_axapi3.py │ ├── a10_service_group.py │ └── a10_virtual_server.py ├── asa │ ├── __init__.py │ ├── asa_acl.py │ ├── asa_command.py │ └── asa_config.py ├── citrix │ ├── __init__.py │ └── netscaler.py ├── cloudflare_dns.py ├── dnsimple.py ├── dnsmadeeasy.py ├── exoscale │ ├── __init__.py │ ├── exo_dns_domain.py │ └── exo_dns_record.py ├── f5 │ ├── __init__.py │ ├── bigip_device_dns.py │ ├── bigip_device_ntp.py │ ├── bigip_device_sshd.py │ ├── bigip_facts.py │ ├── bigip_gtm_datacenter.py │ ├── bigip_gtm_facts.py │ ├── bigip_gtm_virtual_server.py │ ├── bigip_gtm_wide_ip.py │ ├── bigip_hostname.py │ ├── bigip_irule.py │ ├── bigip_monitor_http.py │ ├── bigip_monitor_tcp.py │ ├── bigip_node.py │ ├── bigip_pool.py │ ├── bigip_pool_member.py │ ├── bigip_routedomain.py │ ├── bigip_selfip.py │ ├── bigip_snat_pool.py │ ├── bigip_ssl_certificate.py │ ├── bigip_sys_db.py │ ├── bigip_sys_global.py │ ├── bigip_virtual_server.py │ └── bigip_vlan.py ├── haproxy.py ├── illumos │ ├── __init__.py │ ├── dladm_etherstub.py │ ├── dladm_vnic.py │ ├── flowadm.py │ ├── ipadm_if.py │ └── ipadm_prop.py ├── ipify_facts.py ├── ipinfoio_facts.py ├── lldp.py ├── netconf │ ├── __init__.py │ └── netconf_config.py ├── nmcli.py ├── openvswitch_bridge.py ├── openvswitch_db.py ├── openvswitch_port.py ├── panos │ ├── __init__.py │ └── panos_admin.py ├── snmp_facts.py └── wakeonlan.py ├── notification ├── __init__.py ├── campfire.py ├── flowdock.py ├── grove.py ├── hall.py ├── hipchat.py ├── irc.py ├── jabber.py ├── mail.py ├── mqtt.py ├── nexmo.py ├── osx_say.py ├── pushbullet.py ├── pushover.py ├── rocketchat.py ├── sendgrid.py ├── slack.py ├── sns.py ├── telegram.py ├── twilio.py └── typetalk.py ├── packaging ├── __init__.py ├── dpkg_selections.py ├── elasticsearch_plugin.py ├── kibana_plugin.py ├── language │ ├── __init__.py │ ├── bower.py │ ├── bundler.py │ ├── composer.py │ ├── cpanm.py │ ├── maven_artifact.py │ ├── npm.py │ └── pear.py └── os │ ├── __init__.py │ ├── apk.py │ ├── dnf.py │ ├── homebrew.py │ ├── homebrew_cask.py │ ├── homebrew_tap.py │ ├── layman.py │ ├── macports.py │ ├── openbsd_pkg.py │ ├── opkg.py │ ├── pacman.py │ ├── pkg5.py │ ├── pkg5_publisher.py │ ├── pkgin.py │ ├── pkgng.py │ ├── pkgutil.py │ ├── portage.py │ ├── portinstall.py │ ├── slackpkg.py │ ├── svr4pkg.py │ ├── swdepot.py │ ├── urpmi.py │ ├── xbps.py │ ├── yum_repository.py │ ├── zypper.py │ └── zypper_repository.py ├── remote_management ├── __init__.py └── ipmi │ ├── __init__.py │ ├── ipmi_boot.py │ └── ipmi_power.py ├── source_control ├── __init__.py ├── bzr.py ├── git_config.py ├── github_hooks.py ├── github_key.py ├── github_release.py ├── gitlab_group.py ├── gitlab_project.py └── gitlab_user.py ├── storage ├── __init__.py └── netapp │ ├── README.md │ ├── __init__.py │ ├── netapp_e_amg.py │ ├── netapp_e_amg_role.py │ ├── netapp_e_amg_sync.py │ ├── netapp_e_auth.py │ ├── netapp_e_facts.py │ ├── netapp_e_flashcache.py │ ├── netapp_e_host.py │ ├── netapp_e_hostgroup.py │ ├── netapp_e_lun_mapping.py │ ├── netapp_e_snapshot_group.py │ ├── netapp_e_snapshot_images.py │ ├── netapp_e_snapshot_volume.py │ ├── netapp_e_storage_system.py │ ├── netapp_e_storagepool.py │ ├── netapp_e_volume.py │ └── netapp_e_volume_copy.py ├── system ├── __init__.py ├── alternatives.py ├── at.py ├── capabilities.py ├── cronvar.py ├── crypttab.py ├── debconf.py ├── facter.py ├── filesystem.py ├── firewalld.py ├── getent.py ├── gluster_volume.py ├── iptables.py ├── kernel_blacklist.py ├── known_hosts.py ├── locale_gen.py ├── lvg.py ├── lvol.py ├── make.py ├── modprobe.py ├── ohai.py ├── open_iscsi.py ├── openwrt_init.py ├── osx_defaults.py ├── pam_limits.py ├── puppet.py ├── sefcontext.py ├── selinux_permissive.py ├── seport.py ├── solaris_zone.py ├── svc.py ├── timezone.py ├── ufw.py └── zfs.py ├── test └── utils │ └── shippable │ ├── ci.sh │ ├── docs-requirements.txt │ ├── docs.sh │ ├── integration.sh │ ├── sanity-skip-python24.txt │ └── sanity.sh ├── univention ├── __init__.py ├── udm_dns_record.py ├── udm_dns_zone.py ├── udm_group.py ├── udm_share.py └── udm_user.py ├── web_infrastructure ├── __init__.py ├── apache2_mod_proxy.py ├── deploy_helper.py ├── ejabberd_user.py ├── jboss.py ├── jenkins_job.py ├── jenkins_plugin.py ├── jira.py ├── letsencrypt.py ├── nginx_status_facts.py └── taiga_issue.py └── windows ├── __init__.py ├── win_acl.ps1 ├── win_acl.py ├── win_acl_inheritance.ps1 ├── win_acl_inheritance.py ├── win_chocolatey.ps1 ├── win_chocolatey.py ├── win_dotnet_ngen.ps1 ├── win_dotnet_ngen.py ├── win_environment.ps1 ├── win_environment.py ├── win_file_version.ps1 ├── win_file_version.py ├── win_firewall_rule.ps1 ├── win_firewall_rule.py ├── win_iis_virtualdirectory.ps1 ├── win_iis_virtualdirectory.py ├── win_iis_webapplication.ps1 ├── win_iis_webapplication.py ├── win_iis_webapppool.ps1 ├── win_iis_webapppool.py ├── win_iis_webbinding.ps1 ├── win_iis_webbinding.py ├── win_iis_website.ps1 ├── win_iis_website.py ├── win_nssm.ps1 ├── win_nssm.py ├── win_owner.ps1 ├── win_owner.py ├── win_package.ps1 ├── win_package.py ├── win_regedit.ps1 ├── win_regedit.py ├── win_regmerge.ps1 ├── win_regmerge.py ├── win_robocopy.ps1 ├── win_robocopy.py ├── win_say.ps1 ├── win_say.py ├── win_scheduled_task.ps1 ├── win_scheduled_task.py ├── win_share.ps1 ├── win_share.py ├── win_timezone.ps1 ├── win_timezone.py ├── win_unzip.ps1 ├── win_unzip.py ├── win_updates.ps1 ├── win_updates.py ├── win_uri.ps1 ├── win_uri.py ├── win_webpicmd.ps1 └── win_webpicmd.py /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # This repository is locked 2 | 3 | Please open all new issues and pull requests in https://github.com/ansible/ansible 4 | 5 | For more information please see http://docs.ansible.com/ansible/dev_guide/repomerge.html 6 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # This repository is locked 2 | 3 | Please open all new issues and pull requests in https://github.com/ansible/ansible 4 | 5 | For more information please see http://docs.ansible.com/ansible/dev_guide/repomerge.html 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # build products... 2 | *.py[co] 3 | build 4 | AUTHORS.TXT 5 | # Emacs backup files... 6 | *~ 7 | .\#* 8 | # RPM stuff... 9 | MANIFEST 10 | dist 11 | rpm-build 12 | # Eclipse/PyDev stuff... 13 | .project 14 | .pydevproject 15 | # PyCharm stuff... 16 | .idea 17 | #IntelliJ IDEA stuff.. 18 | *.iml 19 | # Mac OS X stuff... 20 | .DS_Store 21 | # manpage build stuff... 22 | docs/man/man3/* 23 | # Sublime stuff 24 | *.sublime-project 25 | *.sublime-workspace 26 | # docsite stuff... 27 | docsite/rst/modules_by_category.rst 28 | docsite/rst/list_of_*.rst 29 | docsite/rst/*_module.rst 30 | docsite/*.html 31 | docsite/_static/*.gif 32 | docsite/_static/*.png 33 | docsite/_static/websupport.js 34 | docsite/searchindex.js 35 | docsite/htmlout 36 | # deb building stuff... 37 | debian/ 38 | deb-build 39 | # Vim swap files 40 | *.swp 41 | *.swo 42 | credentials.yml 43 | # test output 44 | .coverage 45 | results.xml 46 | coverage.xml 47 | /test/units/cover-html 48 | # Development 49 | /test/develop 50 | venv 51 | Vagrantfile 52 | .vagrant 53 | ansible.egg-info/ 54 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **NOTE:** As of Ansible 2.3, modules are now in the 2 | [main Ansible repository](https://github.com/ansible/ansible/tree/devel/lib/ansible/modules). 3 | 4 | See the [repo merge guide](https://docs.ansible.com/ansible/dev_guide/repomerge.html) for more information. 5 | 6 | This repo still exists to allow bug fixes for `stable-2.2` and older releases. 7 | -------------------------------------------------------------------------------- /cloud/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/cloud/__init__.py -------------------------------------------------------------------------------- /cloud/amazon/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/cloud/amazon/__init__.py -------------------------------------------------------------------------------- /cloud/amazon/ec2_vpc_net_facts.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # This is a free software: you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation, either version 3 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # This Ansible library is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this library. If not, see . 15 | 16 | ANSIBLE_METADATA = {'status': ['stableinterface'], 17 | 'supported_by': 'committer', 18 | 'version': '1.0'} 19 | 20 | DOCUMENTATION = ''' 21 | --- 22 | module: ec2_vpc_net_facts 23 | short_description: Gather facts about ec2 VPCs in AWS 24 | description: 25 | - Gather facts about ec2 VPCs in AWS 26 | version_added: "2.1" 27 | author: "Rob White (@wimnat)" 28 | options: 29 | filters: 30 | description: 31 | - A dict of filters to apply. Each dict item consists of a filter key and a filter value. See U(http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeVpcs.html) for possible filters. 32 | required: false 33 | default: null 34 | 35 | extends_documentation_fragment: 36 | - aws 37 | - ec2 38 | ''' 39 | 40 | EXAMPLES = ''' 41 | # Note: These examples do not set authentication details, see the AWS Guide for details. 42 | 43 | # Gather facts about all VPCs 44 | - ec2_vpc_net_facts: 45 | 46 | # Gather facts about a particular VPC using VPC ID 47 | - ec2_vpc_net_facts: 48 | filters: 49 | vpc-id: vpc-00112233 50 | 51 | # Gather facts about any VPC with a tag key Name and value Example 52 | - ec2_vpc_net_facts: 53 | filters: 54 | "tag:Name": Example 55 | 56 | ''' 57 | 58 | try: 59 | import boto.vpc 60 | from boto.exception import BotoServerError 61 | HAS_BOTO = True 62 | except ImportError: 63 | HAS_BOTO = False 64 | 65 | from ansible.module_utils.basic import AnsibleModule 66 | from ansible.module_utils.ec2 import connect_to_aws, ec2_argument_spec, get_aws_connection_info 67 | 68 | 69 | def get_vpc_info(vpc): 70 | 71 | try: 72 | classic_link = vpc.classic_link_enabled 73 | except AttributeError: 74 | classic_link = False 75 | 76 | vpc_info = { 'id': vpc.id, 77 | 'instance_tenancy': vpc.instance_tenancy, 78 | 'classic_link_enabled': classic_link, 79 | 'dhcp_options_id': vpc.dhcp_options_id, 80 | 'state': vpc.state, 81 | 'is_default': vpc.is_default, 82 | 'cidr_block': vpc.cidr_block, 83 | 'tags': vpc.tags 84 | } 85 | 86 | return vpc_info 87 | 88 | def list_ec2_vpcs(connection, module): 89 | 90 | filters = module.params.get("filters") 91 | vpc_dict_array = [] 92 | 93 | try: 94 | all_vpcs = connection.get_all_vpcs(filters=filters) 95 | except BotoServerError as e: 96 | module.fail_json(msg=e.message) 97 | 98 | for vpc in all_vpcs: 99 | vpc_dict_array.append(get_vpc_info(vpc)) 100 | 101 | module.exit_json(vpcs=vpc_dict_array) 102 | 103 | 104 | def main(): 105 | argument_spec = ec2_argument_spec() 106 | argument_spec.update( 107 | dict( 108 | filters = dict(default=None, type='dict') 109 | ) 110 | ) 111 | 112 | module = AnsibleModule(argument_spec=argument_spec) 113 | 114 | if not HAS_BOTO: 115 | module.fail_json(msg='boto required for this module') 116 | 117 | region, ec2_url, aws_connect_params = get_aws_connection_info(module) 118 | 119 | if region: 120 | try: 121 | connection = connect_to_aws(boto.vpc, region, **aws_connect_params) 122 | except (boto.exception.NoAuthHandlerFound, StandardError) as e: 123 | module.fail_json(msg=str(e)) 124 | else: 125 | module.fail_json(msg="region must be specified") 126 | 127 | list_ec2_vpcs(connection, module) 128 | 129 | 130 | if __name__ == '__main__': 131 | main() 132 | -------------------------------------------------------------------------------- /cloud/amazon/iam_mfa_device_facts.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # This file is part of Ansible 3 | # 4 | # Ansible is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # Ansible is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with Ansible. If not, see . 16 | 17 | ANSIBLE_METADATA = {'status': ['preview'], 18 | 'supported_by': 'community', 19 | 'version': '1.0'} 20 | 21 | DOCUMENTATION = ''' 22 | --- 23 | module: iam_mfa_device_facts 24 | short_description: List the MFA (Multi-Factor Authentication) devices registered for a user 25 | description: 26 | - List the MFA (Multi-Factor Authentication) devices registered for a user 27 | version_added: "2.2" 28 | author: Victor Costan (@pwnall) 29 | options: 30 | user_name: 31 | description: 32 | - The name of the user whose MFA devices will be listed 33 | required: false 34 | default: null 35 | extends_documentation_fragment: 36 | - aws 37 | - ec2 38 | requirements: 39 | - boto3 40 | - botocore 41 | ''' 42 | 43 | RETURN = """ 44 | mfa_devices: 45 | description: The MFA devices registered for the given user 46 | returned: always 47 | type: list 48 | sample: 49 | - enable_date: "2016-03-11T23:25:36+00:00" 50 | serial_number: arn:aws:iam::085120003701:mfa/pwnall 51 | user_name: pwnall 52 | - enable_date: "2016-03-11T23:25:37+00:00" 53 | serial_number: arn:aws:iam::085120003702:mfa/pwnall 54 | user_name: pwnall 55 | """ 56 | 57 | EXAMPLES = ''' 58 | # Note: These examples do not set authentication details, see the AWS Guide for details. 59 | 60 | # List MFA devices (more details: http://docs.aws.amazon.com/IAM/latest/APIReference/API_ListMFADevices.html) 61 | iam_mfa_device_facts: 62 | register: mfa_devices 63 | 64 | # Assume an existing role (more details: http://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html) 65 | sts_assume_role: 66 | mfa_serial_number: "{{ mfa_devices.mfa_devices[0].serial_number }}" 67 | role_arn: "arn:aws:iam::123456789012:role/someRole" 68 | role_session_name: "someRoleSession" 69 | register: assumed_role 70 | ''' 71 | 72 | try: 73 | import boto3 74 | from botocore.exceptions import ClientError 75 | HAS_BOTO3 = True 76 | except ImportError: 77 | HAS_BOTO3 = False 78 | 79 | 80 | def list_mfa_devices(connection, module): 81 | user_name = module.params.get('user_name') 82 | changed = False 83 | 84 | args = {} 85 | if user_name is not None: 86 | args['UserName'] = user_name 87 | try: 88 | response = connection.list_mfa_devices(**args) 89 | except ClientError as e: 90 | module.fail_json(msg=e.message, **camel_dict_to_snake_dict(e.response)) 91 | 92 | module.exit_json(changed=changed, **camel_dict_to_snake_dict(response)) 93 | 94 | 95 | def main(): 96 | argument_spec = ec2_argument_spec() 97 | argument_spec.update( 98 | dict( 99 | user_name=dict(required=False, default=None) 100 | ) 101 | ) 102 | 103 | module = AnsibleModule(argument_spec=argument_spec) 104 | 105 | if not HAS_BOTO3: 106 | module.fail_json(msg='boto3 required for this module') 107 | 108 | region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True) 109 | if region: 110 | connection = boto3_conn(module, conn_type='client', resource='iam', region=region, endpoint=ec2_url, **aws_connect_kwargs) 111 | else: 112 | module.fail_json(msg="region must be specified") 113 | 114 | list_mfa_devices(connection, module) 115 | 116 | 117 | # import module snippets 118 | from ansible.module_utils.basic import * 119 | from ansible.module_utils.ec2 import * 120 | 121 | if __name__ == '__main__': 122 | main() 123 | -------------------------------------------------------------------------------- /cloud/atomic/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/cloud/atomic/__init__.py -------------------------------------------------------------------------------- /cloud/atomic/atomic_host.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # This file is part of Ansible 5 | # 6 | # Ansible is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Ansible is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public licenses 17 | # along with Ansible. If not, see . 18 | 19 | ANSIBLE_METADATA = {'status': ['preview'], 20 | 'supported_by': 'community', 21 | 'version': '1.0'} 22 | 23 | DOCUMENTATION=''' 24 | --- 25 | module: atomic_host 26 | short_description: Manage the atomic host platform 27 | description: 28 | - Manage the atomic host platform 29 | - Rebooting of Atomic host platform should be done outside this module 30 | version_added: "2.2" 31 | author: "Saravanan KR @krsacme" 32 | notes: 33 | - Host should be an atomic platform (verified by existence of '/run/ostree-booted' file) 34 | requirements: 35 | - atomic 36 | - "python >= 2.6" 37 | options: 38 | revision: 39 | description: 40 | - The version number of the atomic host to be deployed. Providing C(latest) will upgrade to the latest available version. 41 | required: false 42 | default: latest 43 | aliases: ["version"] 44 | ''' 45 | 46 | EXAMPLES = ''' 47 | 48 | # Upgrade the atomic host platform to the latest version (atomic host upgrade) 49 | - atomic_host: 50 | revision: latest 51 | 52 | # Deploy a specific revision as the atomic host (atomic host deploy 23.130) 53 | - atomic_host: 54 | revision: 23.130 55 | ''' 56 | 57 | RETURN = ''' 58 | msg: 59 | description: The command standard output 60 | returned: always 61 | type: string 62 | sample: 'Already on latest' 63 | ''' 64 | 65 | def core(module): 66 | revision = module.params['revision'] 67 | args = [] 68 | 69 | module.run_command_environ_update = dict(LANG='C', LC_ALL='C', LC_MESSAGES='C') 70 | 71 | if revision == 'latest': 72 | args = ['atomic', 'host', 'upgrade'] 73 | else: 74 | args = ['atomic', 'host', 'deploy', revision] 75 | 76 | out = {} 77 | err = {} 78 | rc = 0 79 | 80 | rc, out, err = module.run_command(args, check_rc=False) 81 | 82 | if rc == 77 and revision == 'latest': 83 | module.exit_json(msg="Already on latest", changed=False) 84 | elif rc != 0: 85 | module.fail_json(rc=rc, msg=err) 86 | else: 87 | module.exit_json(msg=out, changed=True) 88 | 89 | 90 | def main(): 91 | module = AnsibleModule( 92 | argument_spec = dict( 93 | revision = dict(default='latest', required=False, aliases=["version"]), 94 | ), 95 | ) 96 | 97 | # Verify that the platform is atomic host 98 | if not os.path.exists("/run/ostree-booted"): 99 | module.fail_json(msg="Module atomic_host is applicable for Atomic Host Platforms only") 100 | 101 | try: 102 | core(module) 103 | except Exception as e: 104 | module.fail_json(msg=str(e)) 105 | 106 | 107 | # import module snippets 108 | from ansible.module_utils.basic import * 109 | if __name__ == '__main__': 110 | main() 111 | -------------------------------------------------------------------------------- /cloud/azure/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/cloud/azure/__init__.py -------------------------------------------------------------------------------- /cloud/centurylink/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/cloud/centurylink/__init__.py -------------------------------------------------------------------------------- /cloud/cloudstack/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/cloud/cloudstack/__init__.py -------------------------------------------------------------------------------- /cloud/google/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/cloud/google/__init__.py -------------------------------------------------------------------------------- /cloud/lxc/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/cloud/lxc/__init__.py -------------------------------------------------------------------------------- /cloud/lxd/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/cloud/lxd/__init__.py -------------------------------------------------------------------------------- /cloud/misc/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/cloud/misc/__init__.py -------------------------------------------------------------------------------- /cloud/openstack/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/cloud/openstack/__init__.py -------------------------------------------------------------------------------- /cloud/ovh/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/cloud/ovh/__init__.py -------------------------------------------------------------------------------- /cloud/ovirt/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/cloud/ovirt/__init__.py -------------------------------------------------------------------------------- /cloud/ovirt/ovirt_clusters_facts.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Copyright (c) 2016 Red Hat, Inc. 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | # 21 | 22 | import traceback 23 | 24 | from ansible.module_utils.basic import AnsibleModule 25 | from ansible.module_utils.ovirt import ( 26 | check_sdk, 27 | create_connection, 28 | get_dict_of_struct, 29 | ovirt_full_argument_spec, 30 | ) 31 | 32 | 33 | ANSIBLE_METADATA = {'status': 'preview', 34 | 'supported_by': 'community', 35 | 'version': '1.0'} 36 | 37 | DOCUMENTATION = ''' 38 | --- 39 | module: ovirt_clusters_facts 40 | short_description: Retrieve facts about one or more oVirt clusters 41 | author: "Ondra Machacek (@machacekondra)" 42 | version_added: "2.3" 43 | description: 44 | - "Retrieve facts about one or more oVirt clusters." 45 | notes: 46 | - "This module creates a new top-level C(ovirt_clusters) fact, which 47 | contains a list of clusters." 48 | options: 49 | pattern: 50 | description: 51 | - "Search term which is accepted by oVirt search backend." 52 | - "For example to search cluster X from datacenter Y use following pattern: 53 | name=X and datacenter=Y" 54 | extends_documentation_fragment: ovirt 55 | ''' 56 | 57 | EXAMPLES = ''' 58 | # Examples don't contain auth parameter for simplicity, 59 | # look at ovirt_auth module to see how to reuse authentication: 60 | 61 | # Gather facts about all clusters which names start with C: 62 | - ovirt_clusters_facts: 63 | pattern: name=production* 64 | - debug: 65 | var: ovirt_clusters 66 | ''' 67 | 68 | RETURN = ''' 69 | ovirt_clusters: 70 | description: "List of dictionaries describing the clusters. Cluster attribues are mapped to dictionary keys, 71 | all clusters attributes can be found at following url: https://ovirt.example.com/ovirt-engine/api/model#types/cluster." 72 | returned: On success. 73 | type: list 74 | ''' 75 | 76 | 77 | def main(): 78 | argument_spec = ovirt_full_argument_spec( 79 | pattern=dict(default='', required=False), 80 | ) 81 | module = AnsibleModule(argument_spec) 82 | check_sdk(module) 83 | 84 | try: 85 | connection = create_connection(module.params.pop('auth')) 86 | clusters_service = connection.system_service().clusters_service() 87 | clusters = clusters_service.list(search=module.params['pattern']) 88 | module.exit_json( 89 | changed=False, 90 | ansible_facts=dict( 91 | ovirt_clusters=[ 92 | get_dict_of_struct(c) for c in clusters 93 | ], 94 | ), 95 | ) 96 | except Exception as e: 97 | module.fail_json(msg=str(e), exception=traceback.format_exc()) 98 | finally: 99 | connection.close(logout=False) 100 | 101 | 102 | if __name__ == '__main__': 103 | main() 104 | -------------------------------------------------------------------------------- /cloud/ovirt/ovirt_datacenters_facts.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Copyright (c) 2016 Red Hat, Inc. 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | # 21 | 22 | import traceback 23 | 24 | from ansible.module_utils.basic import AnsibleModule 25 | from ansible.module_utils.ovirt import ( 26 | check_sdk, 27 | create_connection, 28 | get_dict_of_struct, 29 | ovirt_full_argument_spec, 30 | ) 31 | 32 | 33 | ANSIBLE_METADATA = {'status': 'preview', 34 | 'supported_by': 'community', 35 | 'version': '1.0'} 36 | 37 | DOCUMENTATION = ''' 38 | --- 39 | module: ovirt_datacenters_facts 40 | short_description: Retrieve facts about one or more oVirt datacenters 41 | author: "Ondra Machacek (@machacekondra)" 42 | version_added: "2.3" 43 | description: 44 | - "Retrieve facts about one or more oVirt datacenters." 45 | notes: 46 | - "This module creates a new top-level C(ovirt_datacenters) fact, which 47 | contains a list of datacenters." 48 | options: 49 | pattern: 50 | description: 51 | - "Search term which is accepted by oVirt search backend." 52 | - "For example to search datacenter I(X) use following pattern: I(name=X)" 53 | extends_documentation_fragment: ovirt 54 | ''' 55 | 56 | EXAMPLES = ''' 57 | # Examples don't contain auth parameter for simplicity, 58 | # look at ovirt_auth module to see how to reuse authentication: 59 | 60 | # Gather facts about all data centers which names start with C(production): 61 | - ovirt_datacenters_facts: 62 | pattern: name=production* 63 | - debug: 64 | var: ovirt_datacenters 65 | ''' 66 | 67 | RETURN = ''' 68 | ovirt_datacenters: 69 | description: "List of dictionaries describing the datacenters. Datacenter attribues are mapped to dictionary keys, 70 | all datacenters attributes can be found at following url: https://ovirt.example.com/ovirt-engine/api/model#types/data_center." 71 | returned: On success. 72 | type: list 73 | ''' 74 | 75 | 76 | def main(): 77 | argument_spec = ovirt_full_argument_spec( 78 | pattern=dict(default='', required=False), 79 | ) 80 | module = AnsibleModule(argument_spec) 81 | check_sdk(module) 82 | 83 | try: 84 | connection = create_connection(module.params.pop('auth')) 85 | datacenters_service = connection.system_service().data_centers_service() 86 | datacenters = datacenters_service.list(search=module.params['pattern']) 87 | module.exit_json( 88 | changed=False, 89 | ansible_facts=dict( 90 | ovirt_datacenters=[ 91 | get_dict_of_struct(c) for c in datacenters 92 | ], 93 | ), 94 | ) 95 | except Exception as e: 96 | module.fail_json(msg=str(e), exception=traceback.format_exc()) 97 | finally: 98 | connection.close(logout=False) 99 | 100 | 101 | if __name__ == '__main__': 102 | main() 103 | -------------------------------------------------------------------------------- /cloud/ovirt/ovirt_groups_facts.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Copyright (c) 2016 Red Hat, Inc. 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | # 21 | 22 | import traceback 23 | 24 | from ansible.module_utils.basic import AnsibleModule 25 | from ansible.module_utils.ovirt import ( 26 | check_sdk, 27 | create_connection, 28 | get_dict_of_struct, 29 | ovirt_full_argument_spec, 30 | ) 31 | 32 | 33 | ANSIBLE_METADATA = {'status': 'preview', 34 | 'supported_by': 'community', 35 | 'version': '1.0'} 36 | 37 | DOCUMENTATION = ''' 38 | --- 39 | module: ovirt_groups_facts 40 | short_description: Retrieve facts about one or more oVirt groups 41 | author: "Ondra Machacek (@machacekondra)" 42 | version_added: "2.3" 43 | description: 44 | - "Retrieve facts about one or more oVirt groups." 45 | notes: 46 | - "This module creates a new top-level C(ovirt_groups) fact, which 47 | contains a list of groups." 48 | options: 49 | pattern: 50 | description: 51 | - "Search term which is accepted by oVirt search backend." 52 | - "For example to search group X use following pattern: name=X" 53 | extends_documentation_fragment: ovirt 54 | ''' 55 | 56 | EXAMPLES = ''' 57 | # Examples don't contain auth parameter for simplicity, 58 | # look at ovirt_auth module to see how to reuse authentication: 59 | 60 | # Gather facts about all groups which names start with C(admin): 61 | - ovirt_groups_facts: 62 | pattern: name=admin* 63 | - debug: 64 | var: ovirt_groups 65 | ''' 66 | 67 | RETURN = ''' 68 | ovirt_groups: 69 | description: "List of dictionaries describing the groups. Group attribues are mapped to dictionary keys, 70 | all groups attributes can be found at following url: https://ovirt.example.com/ovirt-engine/api/model#types/group." 71 | returned: On success. 72 | type: list 73 | ''' 74 | 75 | 76 | def main(): 77 | argument_spec = ovirt_full_argument_spec( 78 | pattern=dict(default='', required=False), 79 | ) 80 | module = AnsibleModule(argument_spec) 81 | check_sdk(module) 82 | 83 | try: 84 | connection = create_connection(module.params.pop('auth')) 85 | groups_service = connection.system_service().groups_service() 86 | groups = groups_service.list(search=module.params['pattern']) 87 | module.exit_json( 88 | changed=False, 89 | ansible_facts=dict( 90 | ovirt_groups=[ 91 | get_dict_of_struct(c) for c in groups 92 | ], 93 | ), 94 | ) 95 | except Exception as e: 96 | module.fail_json(msg=str(e), exception=traceback.format_exc()) 97 | finally: 98 | connection.close(logout=False) 99 | 100 | 101 | if __name__ == '__main__': 102 | main() 103 | -------------------------------------------------------------------------------- /cloud/ovirt/ovirt_hosts_facts.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Copyright (c) 2016 Red Hat, Inc. 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | # 21 | 22 | try: 23 | import ovirtsdk4 as sdk 24 | except ImportError: 25 | pass 26 | 27 | from ansible.module_utils.ovirt import * 28 | 29 | 30 | ANSIBLE_METADATA = {'status': ['preview'], 31 | 'supported_by': 'community', 32 | 'version': '1.0'} 33 | 34 | DOCUMENTATION = ''' 35 | --- 36 | module: ovirt_hosts_facts 37 | short_description: Retrieve facts about one or more oVirt hosts 38 | author: "Ondra Machacek (@machacekondra)" 39 | version_added: "2.3" 40 | description: 41 | - "Retrieve facts about one or more oVirt hosts." 42 | notes: 43 | - "This module creates a new top-level C(ovirt_hosts) fact, which 44 | contains a list of hosts." 45 | options: 46 | pattern: 47 | description: 48 | - "Search term which is accepted by oVirt search backend." 49 | - "For example to search host X from datacenter Y use following pattern: 50 | name=X and datacenter=Y" 51 | extends_documentation_fragment: ovirt 52 | ''' 53 | 54 | EXAMPLES = ''' 55 | # Examples don't contain auth parameter for simplicity, 56 | # look at ovirt_auth module to see how to reuse authentication: 57 | 58 | # Gather facts about all hosts which names start with C(host) and 59 | # belong to data center C(west): 60 | - ovirt_hosts_facts: 61 | pattern: name=host* and datacenter=west 62 | - debug: 63 | var: ovirt_hosts 64 | ''' 65 | 66 | RETURN = ''' 67 | ovirt_hosts: 68 | description: "List of dictionaries describing the hosts. Host attribues are mapped to dictionary keys, 69 | all hosts attributes can be found at following url: https://ovirt.example.com/ovirt-engine/api/model#types/host." 70 | returned: On success. 71 | type: list 72 | ''' 73 | 74 | 75 | def main(): 76 | argument_spec = ovirt_full_argument_spec( 77 | pattern=dict(default='', required=False), 78 | ) 79 | module = AnsibleModule(argument_spec) 80 | check_sdk(module) 81 | 82 | try: 83 | connection = create_connection(module.params.pop('auth')) 84 | hosts_service = connection.system_service().hosts_service() 85 | hosts = hosts_service.list(search=module.params['pattern']) 86 | module.exit_json( 87 | changed=False, 88 | ansible_facts=dict( 89 | ovirt_hosts=[ 90 | get_dict_of_struct(c) for c in hosts 91 | ], 92 | ), 93 | ) 94 | except Exception as e: 95 | module.fail_json(msg=str(e)) 96 | 97 | from ansible.module_utils.basic import * 98 | if __name__ == '__main__': 99 | main() 100 | -------------------------------------------------------------------------------- /cloud/ovirt/ovirt_networks_facts.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Copyright (c) 2016 Red Hat, Inc. 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | # 21 | 22 | import traceback 23 | 24 | from ansible.module_utils.basic import AnsibleModule 25 | from ansible.module_utils.ovirt import ( 26 | check_sdk, 27 | create_connection, 28 | get_dict_of_struct, 29 | ovirt_full_argument_spec, 30 | ) 31 | 32 | 33 | ANSIBLE_METADATA = {'status': 'preview', 34 | 'supported_by': 'community', 35 | 'version': '1.0'} 36 | 37 | DOCUMENTATION = ''' 38 | --- 39 | module: ovirt_networks_facts 40 | short_description: Retrieve facts about one or more oVirt networks 41 | author: "Ondra Machacek (@machacekondra)" 42 | version_added: "2.3" 43 | description: 44 | - "Retrieve facts about one or more oVirt networks." 45 | notes: 46 | - "This module creates a new top-level C(ovirt_networks) fact, which 47 | contains a list of networks." 48 | options: 49 | pattern: 50 | description: 51 | - "Search term which is accepted by oVirt search backend." 52 | - "For example to search network starting with string vlan1 use: name=vlan1*" 53 | extends_documentation_fragment: ovirt 54 | ''' 55 | 56 | 57 | EXAMPLES = ''' 58 | # Examples don't contain auth parameter for simplicity, 59 | # look at ovirt_auth module to see how to reuse authentication: 60 | 61 | # Gather facts about all networks which names start with C(vlan1): 62 | - ovirt_networks_facts: 63 | pattern: name=vlan1* 64 | - debug: 65 | var: ovirt_networks 66 | ''' 67 | 68 | 69 | RETURN = ''' 70 | ovirt_networks: 71 | description: "List of dictionaries describing the networks. Network attribues are mapped to dictionary keys, 72 | all networks attributes can be found at following url: https://ovirt.example.com/ovirt-engine/api/model#types/network." 73 | returned: On success. 74 | type: list 75 | ''' 76 | 77 | 78 | def main(): 79 | argument_spec = ovirt_full_argument_spec( 80 | pattern=dict(default='', required=False), 81 | ) 82 | module = AnsibleModule(argument_spec) 83 | check_sdk(module) 84 | 85 | try: 86 | connection = create_connection(module.params.pop('auth')) 87 | networks_service = connection.system_service().networks_service() 88 | networks = networks_service.list(search=module.params['pattern']) 89 | module.exit_json( 90 | changed=False, 91 | ansible_facts=dict( 92 | ovirt_networks=[ 93 | get_dict_of_struct(c) for c in networks 94 | ], 95 | ), 96 | ) 97 | except Exception as e: 98 | module.fail_json(msg=str(e), exception=traceback.format_exc()) 99 | finally: 100 | connection.close(logout=False) 101 | 102 | 103 | if __name__ == '__main__': 104 | main() 105 | -------------------------------------------------------------------------------- /cloud/ovirt/ovirt_nics_facts.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Copyright (c) 2016 Red Hat, Inc. 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | # 21 | 22 | import fnmatch 23 | import traceback 24 | 25 | from ansible.module_utils.basic import AnsibleModule 26 | from ansible.module_utils.ovirt import ( 27 | check_sdk, 28 | create_connection, 29 | get_dict_of_struct, 30 | ovirt_full_argument_spec, 31 | search_by_name, 32 | ) 33 | 34 | 35 | ANSIBLE_METADATA = {'status': 'preview', 36 | 'supported_by': 'community', 37 | 'version': '1.0'} 38 | 39 | DOCUMENTATION = ''' 40 | --- 41 | module: ovirt_nics_facts 42 | short_description: Retrieve facts about one or more oVirt virtual machine network interfaces 43 | author: "Ondra Machacek (@machacekondra)" 44 | version_added: "2.3" 45 | description: 46 | - "Retrieve facts about one or more oVirt virtual machine network interfaces." 47 | notes: 48 | - "This module creates a new top-level C(ovirt_nics) fact, which 49 | contains a list of NICs." 50 | options: 51 | vm: 52 | description: 53 | - "Name of the VM where NIC is attached." 54 | required: true 55 | name: 56 | description: 57 | - "Name of the NIC, can be used as glob expression." 58 | extends_documentation_fragment: ovirt 59 | ''' 60 | 61 | EXAMPLES = ''' 62 | # Examples don't contain auth parameter for simplicity, 63 | # look at ovirt_auth module to see how to reuse authentication: 64 | 65 | # Gather facts about all NICs which names start with C(eth) for VM named C(centos7): 66 | - ovirt_nics_facts: 67 | vm: centos7 68 | name: eth* 69 | - debug: 70 | var: ovirt_nics 71 | ''' 72 | 73 | RETURN = ''' 74 | ovirt_nics: 75 | description: "List of dictionaries describing the network interfaces. NIC attribues are mapped to dictionary keys, 76 | all NICs attributes can be found at following url: https://ovirt.example.com/ovirt-engine/api/model#types/nic." 77 | returned: On success. 78 | type: list 79 | ''' 80 | 81 | 82 | def main(): 83 | argument_spec = ovirt_full_argument_spec( 84 | vm=dict(required=True), 85 | name=dict(default=None), 86 | ) 87 | module = AnsibleModule(argument_spec) 88 | check_sdk(module) 89 | 90 | try: 91 | connection = create_connection(module.params.pop('auth')) 92 | vms_service = connection.system_service().vms_service() 93 | vm_name = module.params['vm'] 94 | vm = search_by_name(vms_service, vm_name) 95 | if vm is None: 96 | raise Exception("VM '%s' was not found." % vm_name) 97 | 98 | nics_service = vms_service.service(vm.id).nics_service() 99 | if module.params['name']: 100 | nics = [ 101 | e for e in nics_service.list() 102 | if fnmatch.fnmatch(e.name, module.params['name']) 103 | ] 104 | else: 105 | nics = nics_service.list() 106 | 107 | module.exit_json( 108 | changed=False, 109 | ansible_facts=dict( 110 | ovirt_nics=[ 111 | get_dict_of_struct(c) for c in nics 112 | ], 113 | ), 114 | ) 115 | except Exception as e: 116 | module.fail_json(msg=str(e), exception=traceback.format_exc()) 117 | finally: 118 | connection.close(logout=False) 119 | 120 | 121 | if __name__ == '__main__': 122 | main() 123 | -------------------------------------------------------------------------------- /cloud/ovirt/ovirt_quotas_facts.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Copyright (c) 2016 Red Hat, Inc. 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | # 21 | 22 | import fnmatch 23 | import traceback 24 | 25 | from ansible.module_utils.basic import AnsibleModule 26 | from ansible.module_utils.ovirt import ( 27 | check_sdk, 28 | create_connection, 29 | get_dict_of_struct, 30 | ovirt_full_argument_spec, 31 | search_by_name, 32 | ) 33 | 34 | 35 | ANSIBLE_METADATA = {'status': 'preview', 36 | 'supported_by': 'community', 37 | 'version': '1.0'} 38 | 39 | DOCUMENTATION = ''' 40 | --- 41 | module: ovirt_quotas_facts 42 | short_description: Retrieve facts about one or more oVirt quotas 43 | version_added: "2.3" 44 | description: 45 | - "Retrieve facts about one or more oVirt quotas." 46 | notes: 47 | - "This module creates a new top-level C(ovirt_quotas) fact, which 48 | contains a list of quotas." 49 | options: 50 | datacenter: 51 | description: 52 | - "Name of the datacenter where quota resides." 53 | required: true 54 | name: 55 | description: 56 | - "Name of the quota, can be used as glob expression." 57 | extends_documentation_fragment: ovirt 58 | ''' 59 | 60 | EXAMPLES = ''' 61 | # Examples don't contain auth parameter for simplicity, 62 | # look at ovirt_auth module to see how to reuse authentication: 63 | 64 | # Gather facts about quota named C in Default datacenter: 65 | - ovirt_quotas_facts: 66 | datacenter: Default 67 | name: myquota 68 | - debug: 69 | var: ovirt_quotas 70 | ''' 71 | 72 | RETURN = ''' 73 | ovirt_quotas: 74 | description: "List of dictionaries describing the quotas. Quota attribues are mapped to dictionary keys, 75 | all quotas attributes can be found at following url: https://ovirt.example.com/ovirt-engine/api/model#types/quota." 76 | returned: On success. 77 | type: list 78 | ''' 79 | 80 | 81 | def main(): 82 | argument_spec = ovirt_full_argument_spec( 83 | datacenter=dict(required=True), 84 | name=dict(default=None), 85 | ) 86 | module = AnsibleModule(argument_spec) 87 | check_sdk(module) 88 | 89 | try: 90 | connection = create_connection(module.params.pop('auth')) 91 | datacenters_service = connection.system_service().data_centers_service() 92 | dc_name = module.params['datacenter'] 93 | dc = search_by_name(datacenters_service, dc_name) 94 | if dc is None: 95 | raise Exception("Datacenter '%s' was not found." % dc_name) 96 | 97 | quotas_service = datacenters_service.service(dc.id).quotas_service() 98 | if module.params['name']: 99 | quotas = [ 100 | e for e in quotas_service.list() 101 | if fnmatch.fnmatch(e.name, module.params['name']) 102 | ] 103 | else: 104 | quotas = quotas_service.list() 105 | 106 | module.exit_json( 107 | changed=False, 108 | ansible_facts=dict( 109 | ovirt_quotas=[ 110 | get_dict_of_struct(c) for c in quotas 111 | ], 112 | ), 113 | ) 114 | except Exception as e: 115 | module.fail_json(msg=str(e), exception=traceback.format_exc()) 116 | finally: 117 | connection.close(logout=False) 118 | 119 | 120 | if __name__ == '__main__': 121 | main() 122 | -------------------------------------------------------------------------------- /cloud/ovirt/ovirt_storage_domains_facts.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Copyright (c) 2016 Red Hat, Inc. 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | # 21 | 22 | import traceback 23 | 24 | from ansible.module_utils.basic import AnsibleModule 25 | from ansible.module_utils.ovirt import ( 26 | check_sdk, 27 | create_connection, 28 | get_dict_of_struct, 29 | ovirt_full_argument_spec, 30 | ) 31 | 32 | 33 | ANSIBLE_METADATA = {'status': 'preview', 34 | 'supported_by': 'community', 35 | 'version': '1.0'} 36 | 37 | DOCUMENTATION = ''' 38 | --- 39 | module: ovirt_storage_domains_facts 40 | short_description: Retrieve facts about one or more oVirt storage domains 41 | author: "Ondra Machacek (@machacekondra)" 42 | version_added: "2.3" 43 | description: 44 | - "Retrieve facts about one or more oVirt storage domains." 45 | notes: 46 | - "This module creates a new top-level C(ovirt_storage_domains) fact, which 47 | contains a list of storage domains." 48 | options: 49 | pattern: 50 | description: 51 | - "Search term which is accepted by oVirt search backend." 52 | - "For example to search storage domain X from datacenter Y use following pattern: 53 | name=X and datacenter=Y" 54 | extends_documentation_fragment: ovirt 55 | ''' 56 | 57 | EXAMPLES = ''' 58 | # Examples don't contain auth parameter for simplicity, 59 | # look at ovirt_auth module to see how to reuse authentication: 60 | 61 | # Gather facts about all storage domains which names start with C(data) and 62 | # belong to data center C(west): 63 | - ovirt_storage_domains_facts: 64 | pattern: name=data* and datacenter=west 65 | - debug: 66 | var: ovirt_storage_domains 67 | ''' 68 | 69 | RETURN = ''' 70 | ovirt_storage_domains: 71 | description: "List of dictionaries describing the storage domains. Storage_domain attribues are mapped to dictionary keys, 72 | all storage domains attributes can be found at following url: https://ovirt.example.com/ovirt-engine/api/model#types/storage_domain." 73 | returned: On success. 74 | type: list 75 | ''' 76 | 77 | 78 | def main(): 79 | argument_spec = ovirt_full_argument_spec( 80 | pattern=dict(default='', required=False), 81 | ) 82 | module = AnsibleModule(argument_spec) 83 | check_sdk(module) 84 | 85 | try: 86 | connection = create_connection(module.params.pop('auth')) 87 | storage_domains_service = connection.system_service().storage_domains_service() 88 | storage_domains = storage_domains_service.list(search=module.params['pattern']) 89 | module.exit_json( 90 | changed=False, 91 | ansible_facts=dict( 92 | ovirt_storage_domains=[ 93 | get_dict_of_struct(c) for c in storage_domains 94 | ], 95 | ), 96 | ) 97 | except Exception as e: 98 | module.fail_json(msg=str(e), exception=traceback.format_exc()) 99 | finally: 100 | connection.close(logout=False) 101 | 102 | 103 | if __name__ == '__main__': 104 | main() 105 | -------------------------------------------------------------------------------- /cloud/ovirt/ovirt_templates_facts.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Copyright (c) 2016 Red Hat, Inc. 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | # 21 | 22 | import traceback 23 | 24 | from ansible.module_utils.basic import AnsibleModule 25 | from ansible.module_utils.ovirt import ( 26 | check_sdk, 27 | create_connection, 28 | get_dict_of_struct, 29 | ovirt_full_argument_spec, 30 | ) 31 | 32 | 33 | ANSIBLE_METADATA = {'status': 'preview', 34 | 'supported_by': 'community', 35 | 'version': '1.0'} 36 | 37 | DOCUMENTATION = ''' 38 | --- 39 | module: ovirt_templates_facts 40 | short_description: Retrieve facts about one or more oVirt templates 41 | author: "Ondra Machacek (@machacekondra)" 42 | version_added: "2.3" 43 | description: 44 | - "Retrieve facts about one or more oVirt templates." 45 | notes: 46 | - "This module creates a new top-level C(ovirt_templates) fact, which 47 | contains a list of templates." 48 | options: 49 | pattern: 50 | description: 51 | - "Search term which is accepted by oVirt search backend." 52 | - "For example to search template X from datacenter Y use following pattern: 53 | name=X and datacenter=Y" 54 | extends_documentation_fragment: ovirt 55 | ''' 56 | 57 | EXAMPLES = ''' 58 | # Examples don't contain auth parameter for simplicity, 59 | # look at ovirt_auth module to see how to reuse authentication: 60 | 61 | # Gather facts about all templates which names start with C(centos) and 62 | # belongs to data center C(west): 63 | - ovirt_templates_facts: 64 | pattern: name=centos* and datacenter=west 65 | - debug: 66 | var: ovirt_templates 67 | ''' 68 | 69 | RETURN = ''' 70 | ovirt_templates: 71 | description: "List of dictionaries describing the templates. Template attribues are mapped to dictionary keys, 72 | all templates attributes can be found at following url: https://ovirt.example.com/ovirt-engine/api/model#types/template." 73 | returned: On success. 74 | type: list 75 | ''' 76 | 77 | 78 | def main(): 79 | argument_spec = ovirt_full_argument_spec( 80 | pattern=dict(default='', required=False), 81 | ) 82 | module = AnsibleModule(argument_spec) 83 | check_sdk(module) 84 | 85 | try: 86 | connection = create_connection(module.params.pop('auth')) 87 | templates_service = connection.system_service().templates_service() 88 | templates = templates_service.list(search=module.params['pattern']) 89 | module.exit_json( 90 | changed=False, 91 | ansible_facts=dict( 92 | ovirt_templates=[ 93 | get_dict_of_struct(c) for c in templates 94 | ], 95 | ), 96 | ) 97 | except Exception as e: 98 | module.fail_json(msg=str(e), exception=traceback.format_exc()) 99 | finally: 100 | connection.close(logout=False) 101 | 102 | 103 | if __name__ == '__main__': 104 | main() 105 | -------------------------------------------------------------------------------- /cloud/ovirt/ovirt_users_facts.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Copyright (c) 2016 Red Hat, Inc. 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | # 21 | 22 | import traceback 23 | 24 | from ansible.module_utils.basic import AnsibleModule 25 | from ansible.module_utils.ovirt import ( 26 | check_sdk, 27 | create_connection, 28 | get_dict_of_struct, 29 | ovirt_full_argument_spec, 30 | ) 31 | 32 | 33 | ANSIBLE_METADATA = {'status': 'preview', 34 | 'supported_by': 'community', 35 | 'version': '1.0'} 36 | 37 | DOCUMENTATION = ''' 38 | --- 39 | module: ovirt_users_facts 40 | short_description: Retrieve facts about one or more oVirt users 41 | author: "Ondra Machacek (@machacekondra)" 42 | version_added: "2.3" 43 | description: 44 | - "Retrieve facts about one or more oVirt users." 45 | notes: 46 | - "This module creates a new top-level C(ovirt_users) fact, which 47 | contains a list of users." 48 | options: 49 | pattern: 50 | description: 51 | - "Search term which is accepted by oVirt search backend." 52 | - "For example to search user X use following pattern: name=X" 53 | extends_documentation_fragment: ovirt 54 | ''' 55 | 56 | EXAMPLES = ''' 57 | # Examples don't contain auth parameter for simplicity, 58 | # look at ovirt_auth module to see how to reuse authentication: 59 | 60 | # Gather facts about all users which first names start with C(john): 61 | - ovirt_users_facts: 62 | pattern: name=john* 63 | - debug: 64 | var: ovirt_users 65 | ''' 66 | 67 | RETURN = ''' 68 | ovirt_users: 69 | description: "List of dictionaries describing the users. User attribues are mapped to dictionary keys, 70 | all users attributes can be found at following url: https://ovirt.example.com/ovirt-engine/api/model#types/user." 71 | returned: On success. 72 | type: list 73 | ''' 74 | 75 | 76 | def main(): 77 | argument_spec = ovirt_full_argument_spec( 78 | pattern=dict(default='', required=False), 79 | ) 80 | module = AnsibleModule(argument_spec) 81 | check_sdk(module) 82 | 83 | try: 84 | connection = create_connection(module.params.pop('auth')) 85 | users_service = connection.system_service().users_service() 86 | users = users_service.list(search=module.params['pattern']) 87 | module.exit_json( 88 | changed=False, 89 | ansible_facts=dict( 90 | ovirt_users=[ 91 | get_dict_of_struct(c) for c in users 92 | ], 93 | ), 94 | ) 95 | except Exception as e: 96 | module.fail_json(msg=str(e), exception=traceback.format_exc()) 97 | finally: 98 | connection.close(logout=False) 99 | 100 | 101 | if __name__ == '__main__': 102 | main() 103 | -------------------------------------------------------------------------------- /cloud/ovirt/ovirt_vmpools_facts.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Copyright (c) 2016 Red Hat, Inc. 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | # 21 | 22 | import traceback 23 | 24 | from ansible.module_utils.basic import AnsibleModule 25 | from ansible.module_utils.ovirt import ( 26 | check_sdk, 27 | create_connection, 28 | get_dict_of_struct, 29 | ovirt_full_argument_spec, 30 | ) 31 | 32 | 33 | ANSIBLE_METADATA = {'status': 'preview', 34 | 'supported_by': 'community', 35 | 'version': '1.0'} 36 | 37 | DOCUMENTATION = ''' 38 | --- 39 | module: ovirt_vmpools_facts 40 | short_description: Retrieve facts about one or more oVirt vmpools 41 | author: "Ondra Machacek (@machacekondra)" 42 | version_added: "2.3" 43 | description: 44 | - "Retrieve facts about one or more oVirt vmpools." 45 | notes: 46 | - "This module creates a new top-level C(ovirt_vmpools) fact, which 47 | contains a list of vmpools." 48 | options: 49 | pattern: 50 | description: 51 | - "Search term which is accepted by oVirt search backend." 52 | - "For example to search vmpool X: name=X" 53 | extends_documentation_fragment: ovirt 54 | ''' 55 | 56 | EXAMPLES = ''' 57 | # Examples don't contain auth parameter for simplicity, 58 | # look at ovirt_auth module to see how to reuse authentication: 59 | 60 | # Gather facts about all vm pools which names start with C(centos): 61 | - ovirt_vmpools_facts: 62 | pattern: name=centos* 63 | - debug: 64 | var: ovirt_vmpools 65 | ''' 66 | 67 | RETURN = ''' 68 | ovirt_vm_pools: 69 | description: "List of dictionaries describing the vmpools. Vm pool attribues are mapped to dictionary keys, 70 | all vmpools attributes can be found at following url: https://ovirt.example.com/ovirt-engine/api/model#types/vm_pool." 71 | returned: On success. 72 | type: list 73 | ''' 74 | 75 | 76 | def main(): 77 | argument_spec = ovirt_full_argument_spec( 78 | pattern=dict(default='', required=False), 79 | ) 80 | module = AnsibleModule(argument_spec) 81 | check_sdk(module) 82 | 83 | try: 84 | connection = create_connection(module.params.pop('auth')) 85 | vmpools_service = connection.system_service().vm_pools_service() 86 | vmpools = vmpools_service.list(search=module.params['pattern']) 87 | module.exit_json( 88 | changed=False, 89 | ansible_facts=dict( 90 | ovirt_vm_pools=[ 91 | get_dict_of_struct(c) for c in vmpools 92 | ], 93 | ), 94 | ) 95 | except Exception as e: 96 | module.fail_json(msg=str(e), exception=traceback.format_exc()) 97 | finally: 98 | connection.close(logout=False) 99 | 100 | if __name__ == '__main__': 101 | main() 102 | -------------------------------------------------------------------------------- /cloud/ovirt/ovirt_vms_facts.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Copyright (c) 2016 Red Hat, Inc. 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | # 21 | 22 | import traceback 23 | 24 | from ansible.module_utils.basic import AnsibleModule 25 | from ansible.module_utils.ovirt import ( 26 | check_sdk, 27 | create_connection, 28 | get_dict_of_struct, 29 | ovirt_full_argument_spec, 30 | ) 31 | 32 | 33 | ANSIBLE_METADATA = {'status': 'preview', 34 | 'supported_by': 'community', 35 | 'version': '1.0'} 36 | 37 | DOCUMENTATION = ''' 38 | --- 39 | module: ovirt_vms_facts 40 | short_description: Retrieve facts about one or more oVirt virtual machines 41 | author: "Ondra Machacek (@machacekondra)" 42 | version_added: "2.3" 43 | description: 44 | - "Retrieve facts about one or more oVirt virtual machines." 45 | notes: 46 | - "This module creates a new top-level C(ovirt_vms) fact, which 47 | contains a list of virtual machines." 48 | options: 49 | pattern: 50 | description: 51 | - "Search term which is accepted by oVirt search backend." 52 | - "For example to search VM X from cluster Y use following pattern: 53 | name=X and cluster=Y" 54 | extends_documentation_fragment: ovirt 55 | ''' 56 | 57 | EXAMPLES = ''' 58 | # Examples don't contain auth parameter for simplicity, 59 | # look at ovirt_auth module to see how to reuse authentication: 60 | 61 | # Gather facts about all VMs which names start with C(centos) and 62 | # belong to cluster C(west): 63 | - ovirt_vms_facts: 64 | pattern: name=centos* and cluster=west 65 | - debug: 66 | var: ovirt_vms 67 | ''' 68 | 69 | RETURN = ''' 70 | ovirt_vms: 71 | description: "List of dictionaries describing the VMs. VM attribues are mapped to dictionary keys, 72 | all VMs attributes can be found at following url: https://ovirt.example.com/ovirt-engine/api/model#types/vm." 73 | returned: On success. 74 | type: list 75 | ''' 76 | 77 | 78 | def main(): 79 | argument_spec = ovirt_full_argument_spec( 80 | pattern=dict(default='', required=False), 81 | ) 82 | module = AnsibleModule(argument_spec) 83 | check_sdk(module) 84 | 85 | try: 86 | connection = create_connection(module.params.pop('auth')) 87 | vms_service = connection.system_service().vms_service() 88 | vms = vms_service.list(search=module.params['pattern']) 89 | module.exit_json( 90 | changed=False, 91 | ansible_facts=dict( 92 | ovirt_vms=[ 93 | get_dict_of_struct(c) for c in vms 94 | ], 95 | ), 96 | ) 97 | except Exception as e: 98 | module.fail_json(msg=str(e), exception=traceback.format_exc()) 99 | finally: 100 | connection.close(logout=False) 101 | 102 | 103 | if __name__ == '__main__': 104 | main() 105 | -------------------------------------------------------------------------------- /cloud/profitbricks/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/cloud/profitbricks/__init__.py -------------------------------------------------------------------------------- /cloud/rackspace/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/cloud/rackspace/__init__.py -------------------------------------------------------------------------------- /cloud/smartos/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/cloud/smartos/__init__.py -------------------------------------------------------------------------------- /cloud/smartos/smartos_image_facts.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # (c) 2015, Adam Števko 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | # 21 | 22 | ANSIBLE_METADATA = {'status': ['preview'], 23 | 'supported_by': 'community', 24 | 'version': '1.0'} 25 | 26 | DOCUMENTATION = ''' 27 | --- 28 | module: smartos_image_facts 29 | short_description: Get SmartOS image details. 30 | description: 31 | - Retrieve facts about all installed images on SmartOS. Facts will be 32 | inserted to the ansible_facts key. 33 | version_added: "2.2" 34 | author: Adam Števko (@xen0l) 35 | options: 36 | filters: 37 | description: 38 | - Criteria for selecting image. Can be any value from image 39 | manifest and 'published_date', 'published', 'source', 'clones', 40 | and 'size'. More informaton can be found at U(https://smartos.org/man/1m/imgadm) 41 | under 'imgadm list'. 42 | required: false 43 | default: None 44 | ''' 45 | 46 | EXAMPLES = ''' 47 | # Return facts about all installed images. 48 | smartos_image_facts: 49 | 50 | # Return all private active Linux images. 51 | smartos_image_facts: filters="os=linux state=active public=false" 52 | 53 | # Show, how many clones does every image have. 54 | smartos_image_facts: 55 | 56 | debug: msg="{{ smartos_images[item]['name'] }}-{{smartos_images[item]['version'] }} 57 | has {{ smartos_images[item]['clones'] }} VM(s)" 58 | with_items: "{{ smartos_images.keys() }}" 59 | ''' 60 | 61 | RETURN = ''' 62 | # this module returns ansible_facts 63 | ''' 64 | 65 | try: 66 | import json 67 | except ImportError: 68 | import simplejson as json 69 | 70 | 71 | class ImageFacts(object): 72 | 73 | def __init__(self, module): 74 | self.module = module 75 | 76 | self.filters = module.params['filters'] 77 | 78 | def return_all_installed_images(self): 79 | cmd = [self.module.get_bin_path('imgadm')] 80 | 81 | cmd.append('list') 82 | cmd.append('-j') 83 | 84 | if self.filters: 85 | cmd.append(self.filters) 86 | 87 | (rc, out, err) = self.module.run_command(cmd) 88 | 89 | if rc != 0: 90 | self.module.exit_json( 91 | msg='Failed to get all installed images', stderr=err) 92 | 93 | images = json.loads(out) 94 | 95 | result = {} 96 | for image in images: 97 | result[image['manifest']['uuid']] = image['manifest'] 98 | # Merge additional attributes with the image manifest. 99 | for attrib in ['clones', 'source', 'zpool']: 100 | result[image['manifest']['uuid']][attrib] = image[attrib] 101 | 102 | return result 103 | 104 | 105 | def main(): 106 | module = AnsibleModule( 107 | argument_spec=dict( 108 | filters=dict(default=None), 109 | ), 110 | supports_check_mode=False, 111 | ) 112 | 113 | image_facts = ImageFacts(module) 114 | 115 | data = {} 116 | data['smartos_images'] = image_facts.return_all_installed_images() 117 | 118 | module.exit_json(ansible_facts=data) 119 | 120 | from ansible.module_utils.basic import * 121 | 122 | if __name__ == '__main__': 123 | main() 124 | -------------------------------------------------------------------------------- /cloud/softlayer/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/cloud/softlayer/__init__.py -------------------------------------------------------------------------------- /cloud/vmware/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/cloud/vmware/__init__.py -------------------------------------------------------------------------------- /cloud/vmware/vmware_target_canonical_facts.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # (c) 2015, Joseph Callen 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | 21 | ANSIBLE_METADATA = {'status': ['preview'], 22 | 'supported_by': 'community', 23 | 'version': '1.0'} 24 | 25 | DOCUMENTATION = ''' 26 | --- 27 | module: vmware_target_canonical_facts 28 | short_description: Return canonical (NAA) from an ESXi host 29 | description: 30 | - Return canonical (NAA) from an ESXi host based on SCSI target ID 31 | version_added: "2.0" 32 | author: Joseph Callen 33 | notes: 34 | requirements: 35 | - Tested on vSphere 5.5 36 | - PyVmomi installed 37 | options: 38 | target_id: 39 | description: 40 | - The target id based on order of scsi device 41 | required: True 42 | extends_documentation_fragment: vmware.documentation 43 | ''' 44 | 45 | EXAMPLES = ''' 46 | # Example vmware_target_canonical_facts command from Ansible Playbooks 47 | - name: Get Canonical name 48 | local_action: > 49 | vmware_target_canonical_facts 50 | hostname="{{ ansible_ssh_host }}" username=root password=vmware 51 | target_id=7 52 | ''' 53 | 54 | try: 55 | from pyVmomi import vim, vmodl 56 | HAS_PYVMOMI = True 57 | except ImportError: 58 | HAS_PYVMOMI = False 59 | 60 | 61 | def find_hostsystem(content): 62 | host_system = get_all_objs(content, [vim.HostSystem]) 63 | for host in host_system: 64 | return host 65 | return None 66 | 67 | 68 | def main(): 69 | 70 | argument_spec = vmware_argument_spec() 71 | argument_spec.update(dict(target_id=dict(required=True, type='int'))) 72 | module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=False) 73 | 74 | if not HAS_PYVMOMI: 75 | module.fail_json(msg='pyvmomi is required for this module') 76 | 77 | content = connect_to_api(module) 78 | host = find_hostsystem(content) 79 | 80 | target_lun_uuid = {} 81 | scsilun_canonical = {} 82 | 83 | # Associate the scsiLun key with the canonicalName (NAA) 84 | for scsilun in host.config.storageDevice.scsiLun: 85 | scsilun_canonical[scsilun.key] = scsilun.canonicalName 86 | 87 | # Associate target number with LUN uuid 88 | for target in host.config.storageDevice.scsiTopology.adapter[0].target: 89 | for lun in target.lun: 90 | target_lun_uuid[target.target] = lun.scsiLun 91 | 92 | module.exit_json(changed=False, canonical=scsilun_canonical[target_lun_uuid[module.params['target_id']]]) 93 | 94 | from ansible.module_utils.basic import * 95 | from ansible.module_utils.vmware import * 96 | 97 | if __name__ == '__main__': 98 | main() 99 | 100 | -------------------------------------------------------------------------------- /cloud/vmware/vmware_vm_facts.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # (c) 2015, Joseph Callen 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | 21 | ANSIBLE_METADATA = {'status': ['preview'], 22 | 'supported_by': 'community', 23 | 'version': '1.0'} 24 | 25 | DOCUMENTATION = ''' 26 | --- 27 | module: vmware_vm_facts 28 | short_description: Return basic facts pertaining to a vSphere virtual machine guest 29 | description: 30 | - Return basic facts pertaining to a vSphere virtual machine guest 31 | version_added: 2.0 32 | author: "Joseph Callen (@jcpowermac)" 33 | notes: 34 | - Tested on vSphere 5.5 35 | requirements: 36 | - "python >= 2.6" 37 | - PyVmomi 38 | extends_documentation_fragment: vmware.documentation 39 | ''' 40 | 41 | EXAMPLES = ''' 42 | - name: Gather all registered virtual machines 43 | local_action: 44 | module: vmware_vm_facts 45 | hostname: esxi_or_vcenter_ip_or_hostname 46 | username: username 47 | password: password 48 | ''' 49 | 50 | try: 51 | from pyVmomi import vim, vmodl 52 | HAS_PYVMOMI = True 53 | except ImportError: 54 | HAS_PYVMOMI = False 55 | 56 | 57 | # https://github.com/vmware/pyvmomi-community-samples/blob/master/samples/getallvms.py 58 | def get_all_virtual_machines(content): 59 | virtual_machines = get_all_objs(content, [vim.VirtualMachine]) 60 | _virtual_machines = {} 61 | 62 | for vm in virtual_machines: 63 | _ip_address = "" 64 | summary = vm.summary 65 | if summary.guest is not None: 66 | _ip_address = summary.guest.ipAddress 67 | if _ip_address is None: 68 | _ip_address = "" 69 | 70 | virtual_machine = { 71 | summary.config.name: { 72 | "guest_fullname": summary.config.guestFullName, 73 | "power_state": summary.runtime.powerState, 74 | "ip_address": _ip_address 75 | } 76 | } 77 | 78 | _virtual_machines.update(virtual_machine) 79 | return _virtual_machines 80 | 81 | 82 | def main(): 83 | 84 | argument_spec = vmware_argument_spec() 85 | module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=False) 86 | 87 | if not HAS_PYVMOMI: 88 | module.fail_json(msg='pyvmomi is required for this module') 89 | 90 | try: 91 | content = connect_to_api(module) 92 | _virtual_machines = get_all_virtual_machines(content) 93 | module.exit_json(changed=False, virtual_machines=_virtual_machines) 94 | except vmodl.RuntimeFault as runtime_fault: 95 | module.fail_json(msg=runtime_fault.msg) 96 | except vmodl.MethodFault as method_fault: 97 | module.fail_json(msg=method_fault.msg) 98 | except Exception as e: 99 | module.fail_json(msg=str(e)) 100 | 101 | from ansible.module_utils.vmware import * 102 | from ansible.module_utils.basic import * 103 | 104 | if __name__ == '__main__': 105 | main() 106 | -------------------------------------------------------------------------------- /cloud/webfaction/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/cloud/webfaction/__init__.py -------------------------------------------------------------------------------- /clustering/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/clustering/__init__.py -------------------------------------------------------------------------------- /commands/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/commands/__init__.py -------------------------------------------------------------------------------- /crypto/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/crypto/__init__.py -------------------------------------------------------------------------------- /database/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/database/__init__.py -------------------------------------------------------------------------------- /database/influxdb/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/database/influxdb/__init__.py -------------------------------------------------------------------------------- /database/misc/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/database/misc/__init__.py -------------------------------------------------------------------------------- /database/mssql/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/database/mssql/__init__.py -------------------------------------------------------------------------------- /database/mysql/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/database/mysql/__init__.py -------------------------------------------------------------------------------- /database/postgresql/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/database/postgresql/__init__.py -------------------------------------------------------------------------------- /database/vertica/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/database/vertica/__init__.py -------------------------------------------------------------------------------- /files/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/files/__init__.py -------------------------------------------------------------------------------- /files/tempfile.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | #coding: utf-8 -*- 3 | 4 | # (c) 2016 Krzysztof Magosa 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | 21 | ANSIBLE_METADATA = {'status': ['preview'], 22 | 'supported_by': 'community', 23 | 'version': '1.0'} 24 | 25 | DOCUMENTATION = ''' 26 | --- 27 | module: tempfile 28 | version_added: "2.3" 29 | author: 30 | - Krzysztof Magosa 31 | short_description: Creates temporary files and directories. 32 | description: 33 | - The M(tempfile) module creates temporary files and directories. C(mktemp) command takes different parameters on various systems, this module helps to avoid troubles related to that. Files/directories created by module are accessible only by creator. In case you need to make them world-accessible you need to use M(file) module. 34 | options: 35 | state: 36 | description: 37 | - Whether to create file or directory. 38 | required: false 39 | choices: [ "file", "directory" ] 40 | default: file 41 | path: 42 | description: 43 | - Location where temporary file or directory should be created. If path is not specified default system temporary directory will be used. 44 | required: false 45 | default: null 46 | prefix: 47 | description: 48 | - Prefix of file/directory name created by module. 49 | required: false 50 | default: ansible. 51 | suffix: 52 | description: 53 | - Suffix of file/directory name created by module. 54 | required: false 55 | default: "" 56 | ''' 57 | 58 | EXAMPLES = """ 59 | - name: create temporary build directory 60 | tempfile: 61 | state: directory 62 | suffix: build 63 | 64 | - name: create temporary file 65 | tempfile: 66 | state: file 67 | suffix: temp 68 | """ 69 | 70 | RETURN = ''' 71 | path: 72 | description: Path to created file or directory 73 | returned: success 74 | type: string 75 | sample: "/tmp/ansible.bMlvdk" 76 | ''' 77 | 78 | from ansible.module_utils.basic import AnsibleModule 79 | from ansible.module_utils.pycompat24 import get_exception 80 | from tempfile import mkstemp, mkdtemp 81 | from os import close 82 | 83 | def main(): 84 | module = AnsibleModule( 85 | argument_spec = dict( 86 | state = dict(default='file', choices=['file', 'directory']), 87 | path = dict(default=None), 88 | prefix = dict(default='ansible.'), 89 | suffix = dict(default='') 90 | ) 91 | ) 92 | 93 | try: 94 | if module.params['state'] == 'file': 95 | handle, path = mkstemp( 96 | prefix=module.params['prefix'], 97 | suffix=module.params['suffix'], 98 | dir=module.params['path'] 99 | ) 100 | close(handle) 101 | elif module.params['state'] == 'directory': 102 | path = mkdtemp( 103 | prefix=module.params['prefix'], 104 | suffix=module.params['suffix'], 105 | dir=module.params['path'] 106 | ) 107 | 108 | module.exit_json(changed=True, path=path) 109 | except Exception: 110 | e = get_exception() 111 | module.fail_json(msg=str(e)) 112 | 113 | if __name__ == '__main__': 114 | main() 115 | -------------------------------------------------------------------------------- /identity/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/identity/__init__.py -------------------------------------------------------------------------------- /identity/ipa/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/identity/ipa/__init__.py -------------------------------------------------------------------------------- /identity/opendj/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/identity/opendj/__init__.py -------------------------------------------------------------------------------- /infrastructure/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/infrastructure/__init__.py -------------------------------------------------------------------------------- /infrastructure/foreman/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/infrastructure/foreman/__init__.py -------------------------------------------------------------------------------- /messaging/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/messaging/__init__.py -------------------------------------------------------------------------------- /monitoring/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/monitoring/__init__.py -------------------------------------------------------------------------------- /network/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/network/__init__.py -------------------------------------------------------------------------------- /network/a10/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/network/a10/__init__.py -------------------------------------------------------------------------------- /network/asa/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/network/asa/__init__.py -------------------------------------------------------------------------------- /network/citrix/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/network/citrix/__init__.py -------------------------------------------------------------------------------- /network/exoscale/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/network/exoscale/__init__.py -------------------------------------------------------------------------------- /network/f5/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/network/f5/__init__.py -------------------------------------------------------------------------------- /network/illumos/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/network/illumos/__init__.py -------------------------------------------------------------------------------- /network/ipify_facts.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # (c) 2015, René Moser 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | 21 | ANSIBLE_METADATA = {'status': ['preview'], 22 | 'supported_by': 'community', 23 | 'version': '1.0'} 24 | 25 | DOCUMENTATION = ''' 26 | --- 27 | module: ipify_facts 28 | short_description: Retrieve the public IP of your internet gateway. 29 | description: 30 | - If behind NAT and need to know the public IP of your internet gateway. 31 | version_added: '2.0' 32 | author: "René Moser (@resmo)" 33 | options: 34 | api_url: 35 | description: 36 | - URL of the ipify.org API service. 37 | - C(?format=json) will be appended per default. 38 | required: false 39 | default: 'https://api.ipify.org' 40 | timeout: 41 | description: 42 | - HTTP connection timeout in seconds. 43 | required: false 44 | default: 10 45 | version_added: "2.3" 46 | notes: 47 | - "Visit https://www.ipify.org to get more information." 48 | ''' 49 | 50 | EXAMPLES = ''' 51 | # Gather IP facts from ipify.org 52 | - name: get my public IP 53 | ipify_facts: 54 | 55 | # Gather IP facts from your own ipify service endpoint with a custom timeout 56 | - name: get my public IP 57 | ipify_facts: 58 | api_url: http://api.example.com/ipify 59 | timeout: 20 60 | ''' 61 | 62 | RETURN = ''' 63 | --- 64 | ipify_public_ip: 65 | description: Public IP of the internet gateway. 66 | returned: success 67 | type: string 68 | sample: 1.2.3.4 69 | ''' 70 | 71 | try: 72 | import json 73 | except ImportError: 74 | try: 75 | import simplejson as json 76 | except ImportError: 77 | # Let snippet from module_utils/basic.py return a proper error in this case 78 | pass 79 | 80 | from ansible.module_utils.basic import AnsibleModule 81 | from ansible.module_utils.urls import fetch_url 82 | 83 | 84 | class IpifyFacts(object): 85 | 86 | def __init__(self): 87 | self.api_url = module.params.get('api_url') 88 | self.timeout = module.params.get('timeout') 89 | 90 | def run(self): 91 | result = { 92 | 'ipify_public_ip': None 93 | } 94 | (response, info) = fetch_url(module=module, url=self.api_url + "?format=json" , force=True, timeout=self.timeout) 95 | 96 | if not response: 97 | module.fail_json(msg="No valid or no response from url %s within %s seconds (timeout)" % (self.api_url, self.timeout)) 98 | 99 | data = json.loads(response.read()) 100 | result['ipify_public_ip'] = data.get('ip') 101 | return result 102 | 103 | def main(): 104 | global module 105 | module = AnsibleModule( 106 | argument_spec = dict( 107 | api_url=dict(default='https://api.ipify.org'), 108 | timeout=dict(type='int', default=10), 109 | ), 110 | supports_check_mode=True, 111 | ) 112 | 113 | ipify_facts = IpifyFacts().run() 114 | ipify_facts_result = dict(changed=False, ansible_facts=ipify_facts) 115 | module.exit_json(**ipify_facts_result) 116 | 117 | if __name__ == '__main__': 118 | main() 119 | -------------------------------------------------------------------------------- /network/lldp.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python -tt 2 | # This file is part of Ansible 3 | # 4 | # Ansible is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # Ansible is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with Ansible. If not, see . 16 | 17 | import subprocess 18 | 19 | ANSIBLE_METADATA = {'status': ['preview'], 20 | 'supported_by': 'community', 21 | 'version': '1.0'} 22 | 23 | DOCUMENTATION = ''' 24 | --- 25 | module: lldp 26 | requirements: [ lldpctl ] 27 | version_added: 1.6 28 | short_description: get details reported by lldp 29 | description: 30 | - Reads data out of lldpctl 31 | options: {} 32 | author: "Andy Hill (@andyhky)" 33 | notes: 34 | - Requires lldpd running and lldp enabled on switches 35 | ''' 36 | 37 | EXAMPLES = ''' 38 | # Retrieve switch/port information 39 | - name: Gather information from lldp 40 | lldp: 41 | 42 | - name: Print each switch/port 43 | debug: 44 | msg: "{{ lldp[item]['chassis']['name'] }} / {{ lldp[item]['port']['ifalias'] }}" 45 | with_items: "{{ lldp.keys() }}" 46 | 47 | # TASK: [Print each switch/port] *********************************************************** 48 | # ok: [10.13.0.22] => (item=eth2) => {"item": "eth2", "msg": "switch1.example.com / Gi0/24"} 49 | # ok: [10.13.0.22] => (item=eth1) => {"item": "eth1", "msg": "switch2.example.com / Gi0/3"} 50 | # ok: [10.13.0.22] => (item=eth0) => {"item": "eth0", "msg": "switch3.example.com / Gi0/3"} 51 | 52 | ''' 53 | 54 | def gather_lldp(): 55 | cmd = ['lldpctl', '-f', 'keyvalue'] 56 | proc = subprocess.Popen(cmd, stdout=subprocess.PIPE) 57 | (output, err) = proc.communicate() 58 | if output: 59 | output_dict = {} 60 | lldp_entries = output.split("\n") 61 | 62 | for entry in lldp_entries: 63 | if entry.startswith('lldp'): 64 | path, value = entry.strip().split("=", 1) 65 | path = path.split(".") 66 | path_components, final = path[:-1], path[-1] 67 | else: 68 | value = current_dict[final] + '\n' + entry 69 | 70 | current_dict = output_dict 71 | for path_component in path_components: 72 | current_dict[path_component] = current_dict.get(path_component, {}) 73 | current_dict = current_dict[path_component] 74 | current_dict[final] = value 75 | return output_dict 76 | 77 | 78 | def main(): 79 | module = AnsibleModule({}) 80 | 81 | lldp_output = gather_lldp() 82 | try: 83 | data = {'lldp': lldp_output['lldp']} 84 | module.exit_json(ansible_facts=data) 85 | except TypeError: 86 | module.fail_json(msg="lldpctl command failed. is lldpd running?") 87 | 88 | # import module snippets 89 | from ansible.module_utils.basic import * 90 | 91 | if __name__ == '__main__': 92 | main() 93 | -------------------------------------------------------------------------------- /network/netconf/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/network/netconf/__init__.py -------------------------------------------------------------------------------- /network/panos/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/network/panos/__init__.py -------------------------------------------------------------------------------- /notification/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/notification/__init__.py -------------------------------------------------------------------------------- /notification/grove.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # This file is part of Ansible 5 | # 6 | # Ansible is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Ansible is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with Ansible. If not, see . 18 | 19 | ANSIBLE_METADATA = {'status': ['preview'], 20 | 'supported_by': 'community', 21 | 'version': '1.0'} 22 | 23 | DOCUMENTATION = ''' 24 | --- 25 | module: grove 26 | version_added: 1.4 27 | short_description: Sends a notification to a grove.io channel 28 | description: 29 | - The M(grove) module sends a message for a service to a Grove.io 30 | channel. 31 | options: 32 | channel_token: 33 | description: 34 | - Token of the channel to post to. 35 | required: true 36 | service: 37 | description: 38 | - Name of the service (displayed as the "user" in the message) 39 | required: false 40 | default: ansible 41 | message: 42 | description: 43 | - Message content 44 | required: true 45 | url: 46 | description: 47 | - Service URL for the web client 48 | required: false 49 | icon_url: 50 | description: 51 | - Icon for the service 52 | required: false 53 | validate_certs: 54 | description: 55 | - If C(no), SSL certificates will not be validated. This should only be used 56 | on personally controlled sites using self-signed certificates. 57 | required: false 58 | default: 'yes' 59 | choices: ['yes', 'no'] 60 | version_added: 1.5.1 61 | author: "Jonas Pfenniger (@zimbatm)" 62 | ''' 63 | 64 | EXAMPLES = ''' 65 | - grove: > 66 | channel_token=6Ph62VBBJOccmtTPZbubiPzdrhipZXtg 67 | service=my-app 68 | message=deployed {{ target }} 69 | ''' 70 | 71 | import urllib 72 | 73 | BASE_URL = 'https://grove.io/api/notice/%s/' 74 | 75 | # ============================================================== 76 | # do_notify_grove 77 | 78 | def do_notify_grove(module, channel_token, service, message, url=None, icon_url=None): 79 | my_url = BASE_URL % (channel_token,) 80 | 81 | my_data = dict(service=service, message=message) 82 | if url is not None: 83 | my_data['url'] = url 84 | if icon_url is not None: 85 | my_data['icon_url'] = icon_url 86 | 87 | data = urllib.urlencode(my_data) 88 | response, info = fetch_url(module, my_url, data=data) 89 | if info['status'] != 200: 90 | module.fail_json(msg="failed to send notification: %s" % info['msg']) 91 | 92 | # ============================================================== 93 | # main 94 | 95 | def main(): 96 | module = AnsibleModule( 97 | argument_spec = dict( 98 | channel_token = dict(type='str', required=True, no_log=True), 99 | message = dict(type='str', required=True), 100 | service = dict(type='str', default='ansible'), 101 | url = dict(type='str', default=None), 102 | icon_url = dict(type='str', default=None), 103 | validate_certs = dict(default='yes', type='bool'), 104 | ) 105 | ) 106 | 107 | channel_token = module.params['channel_token'] 108 | service = module.params['service'] 109 | message = module.params['message'] 110 | url = module.params['url'] 111 | icon_url = module.params['icon_url'] 112 | 113 | do_notify_grove(module, channel_token, service, message, url, icon_url) 114 | 115 | # Mission complete 116 | module.exit_json(msg="OK") 117 | 118 | # import module snippets 119 | from ansible.module_utils.basic import * 120 | from ansible.module_utils.urls import * 121 | 122 | if __name__ == '__main__': 123 | main() 124 | -------------------------------------------------------------------------------- /notification/hall.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # (c) 2015, Billy Kimble 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | 21 | 22 | ANSIBLE_METADATA = {'status': ['preview'], 23 | 'supported_by': 'community', 24 | 'version': '1.0'} 25 | 26 | DOCUMENTATION = """ 27 | module: hall 28 | short_description: Send notification to Hall 29 | description: 30 | - "The M(hall) module connects to the U(https://hall.com) messaging API and allows you to deliver notication messages to rooms." 31 | version_added: "2.0" 32 | author: Billy Kimble (@bkimble) 33 | options: 34 | room_token: 35 | description: 36 | - "Room token provided to you by setting up the Ansible room integation on U(https://hall.com)" 37 | required: true 38 | msg: 39 | description: 40 | - The message you wish to deliver as a notifcation 41 | required: true 42 | title: 43 | description: 44 | - The title of the message 45 | required: true 46 | picture: 47 | description: 48 | - "The full URL to the image you wish to use for the Icon of the message. Defaults to U(http://cdn2.hubspot.net/hub/330046/file-769078210-png/Official_Logos/ansible_logo_black_square_small.png?t=1421076128627)" 49 | required: false 50 | """ 51 | 52 | EXAMPLES = """ 53 | - name: Send Hall notifiation 54 | local_action: 55 | module: hall 56 | room_token: 57 | title: Nginx 58 | msg: Created virtual host file on {{ inventory_hostname }} 59 | 60 | - name: Send Hall notification if EC2 servers were created. 61 | when: ec2.instances|length > 0 62 | local_action: 63 | module: hall 64 | room_token: 65 | title: Server Creation 66 | msg: "Created EC2 instance {{ item.id }} of type {{ item.instance_type }}.\\nInstance can be reached at {{ item.public_ip }} in the {{ item.region }} region." 67 | with_items: "{{ ec2.instances }}" 68 | """ 69 | 70 | HALL_API_ENDPOINT = 'https://hall.com/api/1/services/generic/%s' 71 | 72 | def send_request_to_hall(module, room_token, payload): 73 | headers = {'Content-Type': 'application/json'} 74 | payload=module.jsonify(payload) 75 | api_endpoint = HALL_API_ENDPOINT % (room_token) 76 | response, info = fetch_url(module, api_endpoint, data=payload, headers=headers) 77 | if info['status'] != 200: 78 | secure_url = HALL_API_ENDPOINT % ('[redacted]') 79 | module.fail_json(msg=" failed to send %s to %s: %s" % (payload, secure_url, info['msg'])) 80 | 81 | def main(): 82 | module = AnsibleModule( 83 | argument_spec = dict( 84 | room_token = dict(type='str', required=True), 85 | msg = dict(type='str', required=True), 86 | title = dict(type='str', required=True), 87 | picture = dict(type='str', default='http://cdn2.hubspot.net/hub/330046/file-769078210-png/Official_Logos/ansible_logo_black_square_small.png?t=1421076128627'), 88 | ) 89 | ) 90 | 91 | room_token = module.params['room_token'] 92 | message = module.params['msg'] 93 | title = module.params['title'] 94 | picture = module.params['picture'] 95 | payload = {'title': title, 'message': message, 'picture': picture} 96 | send_request_to_hall(module, room_token, payload) 97 | module.exit_json(msg="OK") 98 | 99 | from ansible.module_utils.basic import * 100 | from ansible.module_utils.urls import * 101 | 102 | if __name__ == '__main__': 103 | main() 104 | -------------------------------------------------------------------------------- /notification/osx_say.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # (c) 2013, Michael DeHaan 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | 21 | ANSIBLE_METADATA = {'status': ['stableinterface'], 22 | 'supported_by': 'community', 23 | 'version': '1.0'} 24 | 25 | DOCUMENTATION = ''' 26 | --- 27 | module: osx_say 28 | version_added: "1.2" 29 | short_description: Makes an OSX computer to speak. 30 | description: 31 | - makes an OS computer speak! Amuse your friends, annoy your coworkers! 32 | notes: 33 | - If you like this module, you may also be interested in the osx_say callback in the plugins/ directory of the source checkout. 34 | options: 35 | msg: 36 | description: 37 | What to say 38 | required: true 39 | voice: 40 | description: 41 | What voice to use 42 | required: false 43 | requirements: [ say ] 44 | author: 45 | - "Ansible Core Team" 46 | - "Michael DeHaan (@mpdehaan)" 47 | ''' 48 | 49 | EXAMPLES = ''' 50 | - osx_say: 51 | msg: '{{ inventory_hostname }} is all done' 52 | voice: Zarvox 53 | delegate_to: localhost 54 | ''' 55 | 56 | DEFAULT_VOICE='Trinoids' 57 | 58 | def say(module, msg, voice): 59 | module.run_command(["/usr/bin/say", msg, "--voice=%s" % (voice)], check_rc=True) 60 | 61 | def main(): 62 | 63 | module = AnsibleModule( 64 | argument_spec=dict( 65 | msg=dict(required=True), 66 | voice=dict(required=False, default=DEFAULT_VOICE), 67 | ), 68 | supports_check_mode=False 69 | ) 70 | 71 | if not os.path.exists("/usr/bin/say"): 72 | module.fail_json(msg="/usr/bin/say is not installed") 73 | 74 | msg = module.params['msg'] 75 | voice = module.params['voice'] 76 | 77 | say(module, msg, voice) 78 | 79 | module.exit_json(msg=msg, changed=False) 80 | 81 | # import module snippets 82 | from ansible.module_utils.basic import * 83 | 84 | if __name__ == '__main__': 85 | main() 86 | -------------------------------------------------------------------------------- /notification/pushover.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # Copyright (c) 2012, Jim Richardson 4 | # All rights reserved. 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | 21 | ### 22 | 23 | ANSIBLE_METADATA = {'status': ['preview'], 24 | 'supported_by': 'community', 25 | 'version': '1.0'} 26 | 27 | DOCUMENTATION = ''' 28 | --- 29 | module: pushover 30 | version_added: "2.0" 31 | short_description: Send notifications via U(https://pushover.net) 32 | description: 33 | - Send notifications via pushover, to subscriber list of devices, and email 34 | addresses. Requires pushover app on devices. 35 | notes: 36 | - You will require a pushover.net account to use this module. But no account 37 | is required to receive messages. 38 | options: 39 | msg: 40 | description: 41 | - What message you wish to send. 42 | required: true 43 | app_token: 44 | description: 45 | - Pushover issued token identifying your pushover app. 46 | required: true 47 | user_key: 48 | description: 49 | - Pushover issued authentication key for your user. 50 | required: true 51 | pri: 52 | description: 53 | - Message priority (see U(https://pushover.net) for details.) 54 | required: false 55 | 56 | author: "Jim Richardson (@weaselkeeper)" 57 | ''' 58 | 59 | EXAMPLES = ''' 60 | - pushover: 61 | msg: '{{ inventory_hostname }} has exploded in flames, It is now time to panic' 62 | app_token: wxfdksl 63 | user_key: baa5fe97f2c5ab3ca8f0bb59 64 | delegate_to: localhost 65 | ''' 66 | 67 | import urllib 68 | 69 | 70 | class Pushover(object): 71 | ''' Instantiates a pushover object, use it to send notifications ''' 72 | base_uri = 'https://api.pushover.net' 73 | port = 443 74 | 75 | def __init__(self, module, user, token): 76 | self.module = module 77 | self.user = user 78 | self.token = token 79 | 80 | def run(self, priority, msg): 81 | ''' Do, whatever it is, we do. ''' 82 | 83 | url = '%s:%s/1/messages.json' % (self.base_uri, self.port) 84 | 85 | # parse config 86 | options = dict(user=self.user, 87 | token=self.token, 88 | priority=priority, 89 | message=msg) 90 | data = urllib.urlencode(options) 91 | 92 | headers = { "Content-type": "application/x-www-form-urlencoded"} 93 | r, info = fetch_url(self.module, url, method='POST', data=data, headers=headers) 94 | if info['status'] != 200: 95 | raise Exception(info) 96 | 97 | return r.read() 98 | 99 | 100 | def main(): 101 | 102 | module = AnsibleModule( 103 | argument_spec=dict( 104 | msg=dict(required=True), 105 | app_token=dict(required=True, no_log=True), 106 | user_key=dict(required=True, no_log=True), 107 | pri=dict(required=False, default='0', choices=['-2','-1','0','1','2']), 108 | ), 109 | ) 110 | 111 | msg_object = Pushover(module, module.params['user_key'], module.params['app_token']) 112 | try: 113 | response = msg_object.run(module.params['pri'], module.params['msg']) 114 | except: 115 | module.fail_json(msg='Unable to send msg via pushover') 116 | 117 | module.exit_json(msg='message sent successfully: %s' % response, changed=False) 118 | 119 | # import module snippets 120 | from ansible.module_utils.basic import * 121 | from ansible.module_utils.urls import * 122 | if __name__ == '__main__': 123 | main() 124 | -------------------------------------------------------------------------------- /notification/telegram.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # (c) 2016, Artem Feofanov 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | # 21 | 22 | 23 | ANSIBLE_METADATA = {'status': ['preview'], 24 | 'supported_by': 'community', 25 | 'version': '1.0'} 26 | 27 | DOCUMENTATION = """ 28 | 29 | module: telegram 30 | version_added: "2.2" 31 | author: "Artem Feofanov (@tyouxa)" 32 | 33 | short_description: module for sending notifications via telegram 34 | 35 | description: 36 | - Send notifications via telegram bot, to a verified group or user 37 | notes: 38 | - You will require a telegram account and create telegram bot to use this module. 39 | options: 40 | msg: 41 | description: 42 | - What message you wish to send. 43 | required: true 44 | token: 45 | description: 46 | - Token identifying your telegram bot. 47 | required: true 48 | chat_id: 49 | description: 50 | - Telegram group or user chat_id 51 | required: true 52 | 53 | """ 54 | 55 | EXAMPLES = """ 56 | 57 | send a message to chat in playbook 58 | - telegram: 59 | token: 'bot9999999:XXXXXXXXXXXXXXXXXXXXXXX' 60 | chat_id: 000000 61 | msg: Ansible task finished 62 | """ 63 | 64 | RETURN = """ 65 | 66 | msg: 67 | description: The message you attempted to send 68 | returned: success 69 | type: string 70 | sample: "Ansible task finished" 71 | """ 72 | 73 | import urllib 74 | 75 | def main(): 76 | 77 | module = AnsibleModule( 78 | argument_spec = dict( 79 | token = dict(type='str',required=True,no_log=True), 80 | chat_id = dict(type='str',required=True,no_log=True), 81 | msg = dict(type='str',required=True)), 82 | supports_check_mode=True 83 | ) 84 | 85 | token = urllib.quote(module.params.get('token')) 86 | chat_id = urllib.quote(module.params.get('chat_id')) 87 | msg = urllib.quote(module.params.get('msg')) 88 | 89 | url = 'https://api.telegram.org/' + token + '/sendMessage?text=' + msg + '&chat_id=' + chat_id 90 | 91 | if module.check_mode: 92 | module.exit_json(changed=False) 93 | 94 | response, info = fetch_url(module, url) 95 | if info['status'] == 200: 96 | module.exit_json(changed=True) 97 | else: 98 | module.fail_json(msg="failed to send message, return status=%s" % str(info['status'])) 99 | 100 | 101 | # import module snippets 102 | from ansible.module_utils.basic import * 103 | from ansible.module_utils.urls import * 104 | if __name__ == '__main__': 105 | main() 106 | -------------------------------------------------------------------------------- /packaging/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/packaging/__init__.py -------------------------------------------------------------------------------- /packaging/dpkg_selections.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # This file is part of Ansible 5 | # 6 | # Ansible is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Ansible is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with Ansible. If not, see . 18 | 19 | ANSIBLE_METADATA = {'status': ['preview'], 20 | 'supported_by': 'community', 21 | 'version': '1.0'} 22 | 23 | DOCUMENTATION = ''' 24 | --- 25 | module: dpkg_selections 26 | short_description: Dpkg package selection selections 27 | description: 28 | - Change dpkg package selection state via --get-selections and --set-selections. 29 | version_added: "2.0" 30 | author: Brian Brazil 31 | options: 32 | name: 33 | description: 34 | - Name of the package 35 | required: true 36 | selection: 37 | description: 38 | - The selection state to set the package to. 39 | choices: [ 'install', 'hold', 'deinstall', 'purge' ] 40 | required: true 41 | notes: 42 | - This module won't cause any packages to be installed/removed/purged, use the C(apt) module for that. 43 | ''' 44 | EXAMPLES = ''' 45 | # Prevent python from being upgraded. 46 | - dpkg_selections: 47 | name: python 48 | selection: hold 49 | ''' 50 | 51 | def main(): 52 | module = AnsibleModule( 53 | argument_spec = dict( 54 | name = dict(required=True), 55 | selection = dict(choices=['install', 'hold', 'deinstall', 'purge']) 56 | ), 57 | supports_check_mode=True, 58 | ) 59 | 60 | dpkg = module.get_bin_path('dpkg', True) 61 | 62 | name = module.params['name'] 63 | selection = module.params['selection'] 64 | 65 | # Get current settings. 66 | rc, out, err = module.run_command([dpkg, '--get-selections', name], check_rc=True) 67 | if not out: 68 | current = 'not present' 69 | else: 70 | current = out.split()[1] 71 | 72 | changed = current != selection 73 | 74 | if module.check_mode or not changed: 75 | module.exit_json(changed=changed, before=current, after=selection) 76 | 77 | module.run_command([dpkg, '--set-selections'], data="%s %s" % (name, selection), check_rc=True) 78 | module.exit_json(changed=changed, before=current, after=selection) 79 | 80 | 81 | from ansible.module_utils.basic import * 82 | 83 | if __name__ == '__main__': 84 | main() 85 | -------------------------------------------------------------------------------- /packaging/language/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/packaging/language/__init__.py -------------------------------------------------------------------------------- /packaging/os/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/packaging/os/__init__.py -------------------------------------------------------------------------------- /remote_management/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/remote_management/__init__.py -------------------------------------------------------------------------------- /remote_management/ipmi/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/remote_management/ipmi/__init__.py -------------------------------------------------------------------------------- /source_control/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/source_control/__init__.py -------------------------------------------------------------------------------- /source_control/github_release.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # This file is part of Ansible 5 | # 6 | # Ansible is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Ansible is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with Ansible. If not, see . 18 | 19 | 20 | ANSIBLE_METADATA = {'status': ['preview'], 21 | 'supported_by': 'community', 22 | 'version': '1.0'} 23 | 24 | DOCUMENTATION = ''' 25 | --- 26 | module: github_release 27 | short_description: Interact with GitHub Releases 28 | description: 29 | - Fetch metadata about Github Releases 30 | version_added: 2.2 31 | options: 32 | token: 33 | required: true 34 | description: 35 | - Github Personal Access Token for authenticating 36 | user: 37 | required: true 38 | description: 39 | - The GitHub account that owns the repository 40 | repo: 41 | required: true 42 | description: 43 | - Repository name 44 | action: 45 | required: true 46 | description: 47 | - Action to perform 48 | choices: [ 'latest_release' ] 49 | 50 | author: 51 | - "Adrian Moisey (@adrianmoisey)" 52 | requirements: 53 | - "github3.py >= 1.0.0a3" 54 | ''' 55 | 56 | EXAMPLES = ''' 57 | - name: Get latest release of test/test 58 | github: 59 | token: tokenabc1234567890 60 | user: testuser 61 | repo: testrepo 62 | action: latest_release 63 | ''' 64 | 65 | RETURN = ''' 66 | latest_release: 67 | description: Version of the latest release 68 | type: string 69 | returned: success 70 | sample: 1.1.0 71 | ''' 72 | 73 | try: 74 | import github3 75 | 76 | HAS_GITHUB_API = True 77 | except ImportError: 78 | HAS_GITHUB_API = False 79 | 80 | 81 | def main(): 82 | module = AnsibleModule( 83 | argument_spec=dict( 84 | repo=dict(required=True), 85 | user=dict(required=True), 86 | token=dict(required=True, no_log=True), 87 | action=dict(required=True, choices=['latest_release']), 88 | ), 89 | supports_check_mode=True 90 | ) 91 | 92 | if not HAS_GITHUB_API: 93 | module.fail_json(msg='Missing requried github3 module (check docs or install with: pip install github3)') 94 | 95 | repo = module.params['repo'] 96 | user = module.params['user'] 97 | login_token = module.params['token'] 98 | action = module.params['action'] 99 | 100 | # login to github 101 | try: 102 | gh = github3.login(token=str(login_token)) 103 | # test if we're actually logged in 104 | gh.me() 105 | except github3.AuthenticationFailed: 106 | e = get_exception() 107 | module.fail_json(msg='Failed to connect to Github: %s' % e) 108 | 109 | repository = gh.repository(str(user), str(repo)) 110 | 111 | if not repository: 112 | module.fail_json(msg="Repository %s/%s doesn't exist" % (user, repo)) 113 | 114 | if action == 'latest_release': 115 | release = repository.latest_release() 116 | if release: 117 | module.exit_json(tag=release.tag_name) 118 | else: 119 | module.exit_json(tag=None) 120 | 121 | 122 | from ansible.module_utils.basic import * 123 | 124 | if __name__ == '__main__': 125 | main() 126 | -------------------------------------------------------------------------------- /storage/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/storage/__init__.py -------------------------------------------------------------------------------- /storage/netapp/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/storage/netapp/__init__.py -------------------------------------------------------------------------------- /system/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/system/__init__.py -------------------------------------------------------------------------------- /system/facter.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # (c) 2012, Michael DeHaan 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | # 21 | 22 | 23 | ANSIBLE_METADATA = {'status': ['preview'], 24 | 'supported_by': 'community', 25 | 'version': '1.0'} 26 | 27 | DOCUMENTATION = ''' 28 | --- 29 | module: facter 30 | short_description: Runs the discovery program I(facter) on the remote system 31 | description: 32 | - Runs the I(facter) discovery program 33 | (U(https://github.com/puppetlabs/facter)) on the remote system, returning 34 | JSON data that can be useful for inventory purposes. 35 | version_added: "0.2" 36 | options: {} 37 | notes: [] 38 | requirements: [ "facter", "ruby-json" ] 39 | author: 40 | - "Ansible Core Team" 41 | - "Michael DeHaan" 42 | ''' 43 | 44 | EXAMPLES = ''' 45 | # Example command-line invocation 46 | ansible www.example.net -m facter 47 | ''' 48 | 49 | def main(): 50 | module = AnsibleModule( 51 | argument_spec = dict() 52 | ) 53 | 54 | facter_path = module.get_bin_path('facter', opt_dirs=['/opt/puppetlabs/bin']) 55 | 56 | cmd = [facter_path, "--puppet", "--json"] 57 | 58 | rc, out, err = module.run_command(cmd, check_rc=True) 59 | module.exit_json(**json.loads(out)) 60 | 61 | # import module snippets 62 | from ansible.module_utils.basic import * 63 | 64 | if __name__ == '__main__': 65 | main() 66 | -------------------------------------------------------------------------------- /system/ohai.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # (c) 2012, Michael DeHaan 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | # 21 | 22 | ANSIBLE_METADATA = {'status': ['preview'], 23 | 'supported_by': 'community', 24 | 'version': '1.0'} 25 | 26 | DOCUMENTATION = ''' 27 | --- 28 | module: ohai 29 | short_description: Returns inventory data from I(Ohai) 30 | description: 31 | - Similar to the M(facter) module, this runs the I(Ohai) discovery program 32 | (U(http://wiki.opscode.com/display/chef/Ohai)) on the remote host and 33 | returns JSON inventory data. 34 | I(Ohai) data is a bit more verbose and nested than I(facter). 35 | version_added: "0.6" 36 | options: {} 37 | notes: [] 38 | requirements: [ "ohai" ] 39 | author: 40 | - "Ansible Core Team" 41 | - "Michael DeHaan (@mpdehaan)" 42 | ''' 43 | 44 | EXAMPLES = ''' 45 | # Retrieve (ohai) data from all Web servers and store in one-file per host 46 | ansible webservers -m ohai --tree=/tmp/ohaidata 47 | ''' 48 | 49 | def main(): 50 | module = AnsibleModule( 51 | argument_spec = dict() 52 | ) 53 | cmd = ["/usr/bin/env", "ohai"] 54 | rc, out, err = module.run_command(cmd, check_rc=True) 55 | module.exit_json(**json.loads(out)) 56 | 57 | # import module snippets 58 | from ansible.module_utils.basic import * 59 | 60 | if __name__ == '__main__': 61 | main() 62 | -------------------------------------------------------------------------------- /test/utils/shippable/ci.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -eux 2 | 3 | set -o pipefail 4 | 5 | source_root=$(python -c "from os import path; print(path.abspath(path.join(path.dirname('$0'), '../../..')))") 6 | 7 | "${source_root}/test/utils/shippable/${TEST}.sh" 2>&1 | gawk '{ print strftime("%Y-%m-%d %H:%M:%S"), $0; fflush(); }' 8 | -------------------------------------------------------------------------------- /test/utils/shippable/docs-requirements.txt: -------------------------------------------------------------------------------- 1 | jinja2 2 | pyyaml 3 | -------------------------------------------------------------------------------- /test/utils/shippable/docs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -eux 2 | 3 | set -o pipefail 4 | 5 | ansible_repo_url="https://github.com/ansible/ansible.git" 6 | 7 | build_dir="${SHIPPABLE_BUILD_DIR}" 8 | repo="${REPO_NAME}" 9 | 10 | case "${repo}" in 11 | "ansible-modules-core") 12 | this_module_group="core" 13 | other_module_group="extras" 14 | ;; 15 | "ansible-modules-extras") 16 | this_module_group="extras" 17 | other_module_group="core" 18 | ;; 19 | *) 20 | echo "Unsupported repo name: ${repo}" 21 | exit 1 22 | ;; 23 | esac 24 | 25 | modules_tmp_dir="${build_dir}.tmp" 26 | this_modules_dir="${build_dir}/lib/ansible/modules/${this_module_group}" 27 | other_modules_dir="${build_dir}/lib/ansible/modules/${other_module_group}" 28 | 29 | cd / 30 | mv "${build_dir}" "${modules_tmp_dir}" 31 | git clone "${ansible_repo_url}" "${build_dir}" 32 | cd "${build_dir}" 33 | rmdir "${this_modules_dir}" 34 | mv "${modules_tmp_dir}" "${this_modules_dir}" 35 | mv "${this_modules_dir}/shippable" "${build_dir}" 36 | git submodule init "${other_modules_dir}" 37 | git submodule sync "${other_modules_dir}" 38 | git submodule update "${other_modules_dir}" 39 | 40 | pip install -r lib/ansible/modules/${this_module_group}/test/utils/shippable/docs-requirements.txt --upgrade 41 | pip list 42 | 43 | source hacking/env-setup 44 | 45 | docs_status=0 46 | 47 | PAGER=/bin/cat \ 48 | ANSIBLE_DEPRECATION_WARNINGS=false \ 49 | bin/ansible-doc -l \ 50 | 2>/tmp/ansible-doc.err || docs_status=$? 51 | 52 | if [ -s /tmp/ansible-doc.err ]; then 53 | # report warnings as errors 54 | echo "Output from 'ansible-doc -l' on stderr is considered an error:" 55 | cat /tmp/ansible-doc.err 56 | exit 1 57 | fi 58 | 59 | if [ "${docs_status}" -ne 0 ]; then 60 | echo "Running 'ansible-doc -l' failed with no output on stderr and exit code: ${docs_status}" 61 | exit 1 62 | fi 63 | -------------------------------------------------------------------------------- /test/utils/shippable/integration.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -eux 2 | 3 | set -o pipefail 4 | 5 | ansible_repo_url="https://github.com/ansible/ansible.git" 6 | 7 | is_pr="${IS_PULL_REQUEST}" 8 | build_dir="${SHIPPABLE_BUILD_DIR}" 9 | repo="${REPO_NAME}" 10 | 11 | if [ "${is_pr}" != "true" ]; then 12 | echo "Module integration tests are only supported on pull requests." 13 | exit 0 14 | fi 15 | 16 | case "${repo}" in 17 | "ansible-modules-core") 18 | this_module_group="core" 19 | other_module_group="extras" 20 | ;; 21 | "ansible-modules-extras") 22 | this_module_group="extras" 23 | other_module_group="core" 24 | ;; 25 | *) 26 | echo "Unsupported repo name: ${repo}" 27 | exit 1 28 | ;; 29 | esac 30 | 31 | modules_tmp_dir="${build_dir}.tmp" 32 | this_modules_dir="${build_dir}/lib/ansible/modules/${this_module_group}" 33 | other_modules_dir="${build_dir}/lib/ansible/modules/${other_module_group}" 34 | 35 | cd / 36 | mv "${build_dir}" "${modules_tmp_dir}" 37 | git clone "${ansible_repo_url}" "${build_dir}" 38 | cd "${build_dir}" 39 | rmdir "${this_modules_dir}" 40 | mv "${modules_tmp_dir}" "${this_modules_dir}" 41 | mv "${this_modules_dir}/shippable" "${build_dir}" 42 | git submodule init "${other_modules_dir}" 43 | git submodule sync "${other_modules_dir}" 44 | git submodule update "${other_modules_dir}" 45 | 46 | pip install -r test/utils/shippable/modules/generate-tests-requirements.txt --upgrade 47 | pip list 48 | 49 | source hacking/env-setup 50 | 51 | test/utils/shippable/modules/generate-tests "${this_module_group}" --verbose --output /tmp/integration.sh >/dev/null 52 | 53 | if [ -f /tmp/integration.sh ]; then 54 | /bin/bash -eux /tmp/integration.sh 55 | fi 56 | -------------------------------------------------------------------------------- /test/utils/shippable/sanity-skip-python24.txt: -------------------------------------------------------------------------------- 1 | /cloud/ 2 | /clustering/consul.*.py 3 | /clustering/znode.py 4 | /database/influxdb/ 5 | /database/mssql/ 6 | /monitoring/zabbix.*.py 7 | /network/f5/ 8 | /notification/pushbullet.py 9 | /packaging/language/maven_artifact.py 10 | /packaging/os/dnf.py 11 | /packaging/os/layman.py 12 | /remote_management/ipmi/ 13 | /univention/ 14 | /web_infrastructure/letsencrypt.py 15 | /infrastructure/foreman/ 16 | /network/nmcli.py 17 | -------------------------------------------------------------------------------- /test/utils/shippable/sanity.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -eux 2 | 3 | source_root=$(python -c "from os import path; print(path.abspath(path.join(path.dirname('$0'), '../../..')))") 4 | 5 | install_deps="${INSTALL_DEPS:-}" 6 | 7 | cd "${source_root}" 8 | 9 | # FIXME REPOMERGE: No need to checkout ansible 10 | build_dir=$(mktemp -d) 11 | trap 'rm -rf "${build_dir}"' EXIT 12 | 13 | git clone "https://github.com/ansible/ansible.git" "${build_dir}" --recursive 14 | source "${build_dir}/hacking/env-setup" 15 | # REPOMERGE: END 16 | 17 | if [ "${install_deps}" != "" ]; then 18 | add-apt-repository ppa:fkrull/deadsnakes 19 | apt-add-repository 'deb http://archive.ubuntu.com/ubuntu trusty-backports universe' 20 | apt-get update -qq 21 | 22 | apt-get install -qq shellcheck python2.4 23 | 24 | # Install dependencies for ansible and validate_modules 25 | pip install -r "${build_dir}/test/utils/shippable/sanity-requirements.txt" --upgrade 26 | pip list 27 | 28 | fi 29 | 30 | validate_modules="${build_dir}/test/sanity/validate-modules/validate-modules" 31 | 32 | python2.4 -m compileall -fq -x "($(printf %s "$(< "test/utils/shippable/sanity-skip-python24.txt"))" | tr '\n' '|')" . 33 | python2.6 -m compileall -fq . 34 | python2.7 -m compileall -fq . 35 | python3.5 -m compileall -fq . 36 | 37 | ANSIBLE_DEPRECATION_WARNINGS=false \ 38 | "${validate_modules}" --exclude '/utilities/|/shippable(/|$)' . 39 | 40 | shellcheck \ 41 | test/utils/shippable/*.sh 42 | -------------------------------------------------------------------------------- /univention/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/univention/__init__.py -------------------------------------------------------------------------------- /web_infrastructure/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/web_infrastructure/__init__.py -------------------------------------------------------------------------------- /windows/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-extras/f216ba8e0616bc8ad8794c22d4b48e1ab18886cf/windows/__init__.py -------------------------------------------------------------------------------- /windows/win_acl_inheritance.ps1: -------------------------------------------------------------------------------- 1 | #!powershell 2 | # This file is part of Ansible 3 | # 4 | # Copyright 2015, Hans-Joachim Kliemeck 5 | # 6 | # Ansible is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Ansible is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with Ansible. If not, see . 18 | 19 | # WANT_JSON 20 | # POWERSHELL_COMMON 21 | 22 | 23 | $params = Parse-Args $args; 24 | 25 | $result = New-Object PSObject; 26 | Set-Attr $result "changed" $false; 27 | 28 | $path = Get-Attr $params "path" -failifempty $true 29 | $state = Get-Attr $params "state" "absent" -validateSet "present","absent" -resultobj $result 30 | $reorganize = Get-Attr $params "reorganize" "no" -validateSet "no","yes" -resultobj $result 31 | $reorganize = $reorganize | ConvertTo-Bool 32 | 33 | If (-Not (Test-Path -Path $path)) { 34 | Fail-Json $result "$path file or directory does not exist on the host" 35 | } 36 | 37 | Try { 38 | $objACL = Get-ACL $path 39 | $inheritanceEnabled = !$objACL.AreAccessRulesProtected 40 | 41 | If (($state -eq "present") -And !$inheritanceEnabled) { 42 | # second parameter is ignored if first=$False 43 | $objACL.SetAccessRuleProtection($False, $False) 44 | 45 | If ($reorganize) { 46 | # it wont work without intermediate save, state would be the same 47 | Set-ACL $path $objACL 48 | $objACL = Get-ACL $path 49 | 50 | # convert explicit ACE to inherited ACE 51 | ForEach($inheritedRule in $objACL.Access) { 52 | If (!$inheritedRule.IsInherited) { 53 | Continue 54 | } 55 | 56 | ForEach($explicitRrule in $objACL.Access) { 57 | If ($explicitRrule.IsInherited) { 58 | Continue 59 | } 60 | 61 | If (($inheritedRule.FileSystemRights -eq $explicitRrule.FileSystemRights) -And ($inheritedRule.AccessControlType -eq $explicitRrule.AccessControlType) -And ($inheritedRule.IdentityReference -eq $explicitRrule.IdentityReference) -And ($inheritedRule.InheritanceFlags -eq $explicitRrule.InheritanceFlags) -And ($inheritedRule.PropagationFlags -eq $explicitRrule.PropagationFlags)) { 62 | $objACL.RemoveAccessRule($explicitRrule) 63 | } 64 | } 65 | } 66 | } 67 | 68 | Set-ACL $path $objACL 69 | Set-Attr $result "changed" $true; 70 | } 71 | Elseif (($state -eq "absent") -And $inheritanceEnabled) { 72 | If ($reorganize) { 73 | $objACL.SetAccessRuleProtection($True, $True) 74 | } Else { 75 | $objACL.SetAccessRuleProtection($True, $False) 76 | } 77 | 78 | Set-ACL $path $objACL 79 | Set-Attr $result "changed" $true; 80 | } 81 | } 82 | Catch { 83 | Fail-Json $result "an error occured when attempting to disable inheritance" 84 | } 85 | 86 | Exit-Json $result 87 | -------------------------------------------------------------------------------- /windows/win_acl_inheritance.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # Copyright 2015, Hans-Joachim Kliemeck 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | 21 | # this is a windows documentation stub. actual code lives in the .ps1 22 | # file of the same name 23 | 24 | ANSIBLE_METADATA = {'status': ['preview'], 25 | 'supported_by': 'core', 26 | 'version': '1.0'} 27 | 28 | DOCUMENTATION = ''' 29 | --- 30 | module: win_acl_inheritance 31 | version_added: "2.1" 32 | short_description: Change ACL inheritance 33 | description: 34 | - Change ACL (Access Control List) inheritance and optionally copy inherited ACE's (Access Control Entry) to dedicated ACE's or vice versa. 35 | options: 36 | path: 37 | description: 38 | - Path to be used for changing inheritance 39 | required: true 40 | state: 41 | description: 42 | - Specify whether to enable I(present) or disable I(absent) ACL inheritance 43 | required: false 44 | choices: 45 | - present 46 | - absent 47 | default: absent 48 | reorganize: 49 | description: 50 | - For P(state) = I(absent), indicates if the inherited ACE's should be copied from the parent directory. This is necessary (in combination with removal) for a simple ACL instead of using multiple ACE deny entries. 51 | - For P(state) = I(present), indicates if the inherited ACE's should be deduplicated compared to the parent directory. This removes complexity of the ACL structure. 52 | required: false 53 | choices: 54 | - no 55 | - yes 56 | default: no 57 | author: Hans-Joachim Kliemeck (@h0nIg) 58 | ''' 59 | 60 | EXAMPLES = ''' 61 | # Playbook example 62 | --- 63 | - name: Disable inherited ACE's 64 | win_acl_inheritance: 65 | path: 'C:\\apache\\' 66 | state: absent 67 | 68 | - name: Disable and copy inherited ACE's 69 | win_acl_inheritance: 70 | path: 'C:\\apache\\' 71 | state: absent 72 | reorganize: yes 73 | 74 | - name: Enable and remove dedicated ACE's 75 | win_acl_inheritance: 76 | path: 'C:\\apache\\' 77 | state: present 78 | reorganize: yes 79 | ''' 80 | 81 | RETURN = ''' 82 | 83 | ''' -------------------------------------------------------------------------------- /windows/win_chocolatey.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # (c) 2014, Trond Hindenes 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | 21 | # this is a windows documentation stub. actual code lives in the .ps1 22 | # file of the same name 23 | 24 | ANSIBLE_METADATA = {'status': ['preview'], 25 | 'supported_by': 'committer', 26 | 'version': '1.0'} 27 | 28 | DOCUMENTATION = ''' 29 | --- 30 | module: win_chocolatey 31 | version_added: "1.9" 32 | short_description: Installs packages using chocolatey 33 | description: 34 | - Installs packages using Chocolatey (http://chocolatey.org/). If Chocolatey is missing from the system, the module will install it. List of packages can be found at http://chocolatey.org/packages 35 | options: 36 | name: 37 | description: 38 | - Name of the package to be installed 39 | required: true 40 | state: 41 | description: 42 | - State of the package on the system 43 | choices: 44 | - present 45 | - absent 46 | default: present 47 | force: 48 | description: 49 | - Forces install of the package (even if it already exists). Using Force will cause ansible to always report that a change was made 50 | choices: 51 | - yes 52 | - no 53 | default: no 54 | upgrade: 55 | description: 56 | - If package is already installed it, try to upgrade to the latest version or to the specified version 57 | choices: 58 | - yes 59 | - no 60 | default: no 61 | version: 62 | description: 63 | - Specific version of the package to be installed 64 | - Ignored when state == 'absent' 65 | source: 66 | description: 67 | - Specify source rather than using default chocolatey repository 68 | install_args: 69 | description: 70 | - Arguments to pass to the native installer 71 | version_added: '2.1' 72 | params: 73 | description: 74 | - Parameters to pass to the package 75 | version_added: '2.1' 76 | allow_empty_checksums: 77 | description: 78 | - Allow empty Checksums to be used 79 | require: false 80 | default: false 81 | version_added: '2.2' 82 | ignore_checksums: 83 | description: 84 | - Ignore Checksums 85 | require: false 86 | default: false 87 | version_added: '2.2' 88 | ignore_dependencies: 89 | description: 90 | - Ignore dependencies, only install/upgrade the package itself 91 | default: false 92 | version_added: '2.1' 93 | author: "Trond Hindenes (@trondhindenes), Peter Mounce (@petemounce), Pepe Barbe (@elventear), Adam Keech (@smadam813)" 94 | ''' 95 | 96 | # TODO: 97 | # * Better parsing when a package has dependencies - currently fails 98 | # * Time each item that is run 99 | # * Support 'changed' with gems - would require shelling out to `gem list` first and parsing, kinda defeating the point of using chocolatey. 100 | 101 | EXAMPLES = ''' 102 | # Install git 103 | win_chocolatey: 104 | name: git 105 | 106 | # Install notepadplusplus version 6.6 107 | win_chocolatey: 108 | name: notepadplusplus.install 109 | version: '6.6' 110 | 111 | # Uninstall git 112 | win_chocolatey: 113 | name: git 114 | state: absent 115 | 116 | # Install git from specified repository 117 | win_chocolatey: 118 | name: git 119 | source: https://someserver/api/v2/ 120 | ''' 121 | -------------------------------------------------------------------------------- /windows/win_dotnet_ngen.ps1: -------------------------------------------------------------------------------- 1 | #!powershell 2 | # This file is part of Ansible 3 | # 4 | # Copyright 2015, Peter Mounce 5 | # 6 | # Ansible is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Ansible is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with Ansible. If not, see . 18 | 19 | $ErrorActionPreference = "Stop" 20 | 21 | # WANT_JSON 22 | # POWERSHELL_COMMON 23 | 24 | $params = Parse-Args $args; 25 | $result = New-Object PSObject; 26 | Set-Attr $result "changed" $false; 27 | 28 | function Invoke-NGen 29 | { 30 | [CmdletBinding()] 31 | 32 | param 33 | ( 34 | [Parameter(Mandatory=$false, Position=0)] [string] $arity = "" 35 | ) 36 | 37 | if ($arity -eq $null) 38 | { 39 | $arity = "" 40 | } 41 | $cmd = "$($env:windir)\microsoft.net\framework$($arity)\v4.0.30319\ngen.exe" 42 | if (test-path $cmd) 43 | { 44 | $update = Invoke-Expression "$cmd update /force"; 45 | Set-Attr $result "dotnet_ngen$($arity)_update_exit_code" $lastexitcode 46 | Set-Attr $result "dotnet_ngen$($arity)_update_output" $update 47 | $eqi = Invoke-Expression "$cmd executequeueditems"; 48 | Set-Attr $result "dotnet_ngen$($arity)_eqi_exit_code" $lastexitcode 49 | Set-Attr $result "dotnet_ngen$($arity)_eqi_output" $eqi 50 | 51 | $result.changed = $true 52 | } 53 | else 54 | { 55 | Write-Host "Not found: $cmd" 56 | } 57 | } 58 | 59 | Try 60 | { 61 | Invoke-NGen 62 | Invoke-NGen -arity "64" 63 | 64 | Exit-Json $result; 65 | } 66 | Catch 67 | { 68 | Fail-Json $result $_.Exception.Message 69 | } 70 | -------------------------------------------------------------------------------- /windows/win_dotnet_ngen.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # (c) 2015, Peter Mounce 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | 21 | # this is a windows documentation stub. actual code lives in the .ps1 22 | # file of the same name 23 | 24 | ANSIBLE_METADATA = {'status': ['preview'], 25 | 'supported_by': 'community', 26 | 'version': '1.0'} 27 | 28 | DOCUMENTATION = ''' 29 | --- 30 | module: win_dotnet_ngen 31 | version_added: "2.0" 32 | short_description: Runs ngen to recompile DLLs after .NET updates 33 | description: 34 | - After .NET framework is installed/updated, Windows will probably want to recompile things to optimise for the host. 35 | - This happens via scheduled task, usually at some inopportune time. 36 | - This module allows you to run this task on your own schedule, so you incur the CPU hit at some more convenient and controlled time. 37 | - "http://blogs.msdn.com/b/dotnet/archive/2013/08/06/wondering-why-mscorsvw-exe-has-high-cpu-usage-you-can-speed-it-up.aspx" 38 | notes: 39 | - there are in fact two scheduled tasks for ngen but they have no triggers so aren't a problem 40 | - there's no way to test if they've been completed (?) 41 | - the stdout is quite likely to be several megabytes 42 | author: Peter Mounce 43 | ''' 44 | 45 | EXAMPLES = ''' 46 | # Run ngen tasks 47 | win_dotnet_ngen: 48 | ''' 49 | -------------------------------------------------------------------------------- /windows/win_environment.ps1: -------------------------------------------------------------------------------- 1 | #!powershell 2 | # This file is part of Ansible 3 | # 4 | # Copyright 2015, Jon Hawkesworth (@jhawkesworth) 5 | # 6 | # Ansible is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Ansible is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with Ansible. If not, see . 18 | 19 | # WANT_JSON 20 | # POWERSHELL_COMMON 21 | 22 | $params = Parse-Args $args; 23 | $state = Get-AnsibleParam -obj $params -name "state" -default "present" -validateSet "present","absent" 24 | $name = Get-AnsibleParam -obj $params -name "name" -failifempty $true 25 | $level = Get-AnsibleParam -obj $params -name "level" -validateSet "machine","process","user" -failifempty $true 26 | $value = Get-AnsibleParam -obj $params -name "value" 27 | 28 | If ($level) { 29 | $level = $level.ToString().ToLower() 30 | } 31 | 32 | $before_value = [Environment]::GetEnvironmentVariable($name, $level) 33 | 34 | $state = $state.ToString().ToLower() 35 | if ($state -eq "present" ) { 36 | [Environment]::SetEnvironmentVariable($name, $value, $level) 37 | } Elseif ($state -eq "absent") { 38 | [Environment]::SetEnvironmentVariable($name, $null, $level) 39 | } 40 | 41 | $after_value = [Environment]::GetEnvironmentVariable($name, $level) 42 | 43 | $result = New-Object PSObject; 44 | Set-Attr $result "changed" $false; 45 | Set-Attr $result "name" $name; 46 | Set-Attr $result "before_value" $before_value; 47 | Set-Attr $result "value" $after_value; 48 | Set-Attr $result "level" $level; 49 | if ($before_value -ne $after_value) { 50 | Set-Attr $result "changed" $true; 51 | } 52 | 53 | Exit-Json $result; 54 | -------------------------------------------------------------------------------- /windows/win_environment.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # (c) 2015, Jon Hawkesworth (@jhawkesworth) 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | 21 | # this is a windows documentation stub. actual code lives in the .ps1 22 | # file of the same name 23 | 24 | ANSIBLE_METADATA = {'status': ['preview'], 25 | 'supported_by': 'community', 26 | 'version': '1.0'} 27 | 28 | DOCUMENTATION = ''' 29 | --- 30 | module: win_environment 31 | version_added: "2.0" 32 | short_description: Modifies environment variables on windows hosts. 33 | description: 34 | - Uses .net Environment to set or remove environment variables and can set at User, Machine or Process level. 35 | - User level environment variables will be set, but not available until the user has logged off and on again. 36 | options: 37 | state: 38 | description: 39 | - present to ensure environment variable is set, or absent to ensure it is removed 40 | required: false 41 | default: present 42 | choices: 43 | - present 44 | - absent 45 | name: 46 | description: 47 | - The name of the environment variable 48 | required: true 49 | default: no default 50 | value: 51 | description: 52 | - The value to store in the environment variable. Can be omitted for state=absent 53 | required: false 54 | default: no default 55 | level: 56 | description: 57 | - The level at which to set the environment variable. 58 | - Use 'machine' to set for all users. 59 | - Use 'user' to set for the current user that ansible is connected as. 60 | - Use 'process' to set for the current process. Probably not that useful. 61 | required: true 62 | default: no default 63 | choices: 64 | - machine 65 | - process 66 | - user 67 | author: "Jon Hawkesworth (@jhawkesworth)" 68 | notes: 69 | - This module does not broadcast change events. 70 | This means that the minority of windows applications which can have 71 | their environment changed without restarting will not be notified and 72 | therefore will need restarting to pick up new environment settings. 73 | User level environment variables will require the user to log out 74 | and in again before they become available. 75 | ''' 76 | 77 | EXAMPLES = ''' 78 | # Set an environment variable for all users 79 | win_environment: 80 | state: present 81 | name: TestVariable 82 | value: "Test value" 83 | level: machine 84 | # Remove an environment variable for the current users 85 | win_environment: 86 | state: absent 87 | name: TestVariable 88 | level: user 89 | ''' 90 | 91 | -------------------------------------------------------------------------------- /windows/win_file_version.ps1: -------------------------------------------------------------------------------- 1 | #!powershell 2 | 3 | #this file is part of Ansible 4 | #Copyright © 2015 Sam Liu 5 | 6 | #This program is free software: you can redistribute it and/or modify 7 | #it under the terms of the GNU General Public License as published by 8 | #the Free Software Foundation, either version 3 of the License, or 9 | #(at your option) any later version. 10 | 11 | #This program is distributed in the hope that it will be useful, 12 | #but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | #GNU General Public License for more details. 15 | 16 | #You should have received a copy of the GNU General Public License 17 | #along with this program. If not, see . 18 | 19 | # WANT_JSON 20 | # POWERSHELL_COMMON 21 | 22 | $params = Parse-Args $args; 23 | 24 | $result = New-Object psobject @{ 25 | win_file_version = New-Object psobject 26 | changed = $false 27 | } 28 | 29 | $path = Get-AnsibleParam $params "path" -failifempty $true -resultobj $result 30 | 31 | If (-Not (Test-Path -Path $path -PathType Leaf)){ 32 | Fail-Json $result "Specfied path $path does exist or is not a file." 33 | } 34 | $ext = [System.IO.Path]::GetExtension($path) 35 | If ( $ext -notin '.exe', '.dll'){ 36 | Fail-Json $result "Specfied path $path is not a vaild file type; must be DLL or EXE." 37 | } 38 | 39 | Try { 40 | $_version_fields = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($path) 41 | $file_version = $_version_fields.FileVersion 42 | If ($file_version -eq $null){ 43 | $file_version = '' 44 | } 45 | $product_version = $_version_fields.ProductVersion 46 | If ($product_version -eq $null){ 47 | $product_version= '' 48 | } 49 | $file_major_part = $_version_fields.FileMajorPart 50 | If ($file_major_part -eq $null){ 51 | $file_major_part= '' 52 | } 53 | $file_minor_part = $_version_fields.FileMinorPart 54 | If ($file_minor_part -eq $null){ 55 | $file_minor_part= '' 56 | } 57 | $file_build_part = $_version_fields.FileBuildPart 58 | If ($file_build_part -eq $null){ 59 | $file_build_part = '' 60 | } 61 | $file_private_part = $_version_fields.FilePrivatePart 62 | If ($file_private_part -eq $null){ 63 | $file_private_part = '' 64 | } 65 | } 66 | Catch{ 67 | Fail-Json $result "Error: $_.Exception.Message" 68 | } 69 | 70 | Set-Attr $result.win_file_version "path" $path.toString() 71 | Set-Attr $result.win_file_version "file_version" $file_version.toString() 72 | Set-Attr $result.win_file_version "product_version" $product_version.toString() 73 | Set-Attr $result.win_file_version "file_major_part" $file_major_part.toString() 74 | Set-Attr $result.win_file_version "file_minor_part" $file_minor_part.toString() 75 | Set-Attr $result.win_file_version "file_build_part" $file_build_part.toString() 76 | Set-Attr $result.win_file_version "file_private_part" $file_private_part.toString() 77 | Exit-Json $result; 78 | 79 | -------------------------------------------------------------------------------- /windows/win_file_version.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # Get DLL or EXE build version 5 | # Copyright © 2015 Sam Liu 6 | 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | 20 | ANSIBLE_METADATA = {'status': ['preview'], 21 | 'supported_by': 'community', 22 | 'version': '1.0'} 23 | 24 | DOCUMENTATION = ''' 25 | --- 26 | module: win_file_version 27 | version_added: "2.1" 28 | short_description: Get DLL or EXE file build version 29 | description: 30 | - Get DLL or EXE file build version 31 | - change state alway be false 32 | options: 33 | path: 34 | description: 35 | - File to get version(provide absolute path) 36 | required: true 37 | aliases: [] 38 | author: Sam Liu 39 | ''' 40 | 41 | EXAMPLES = ''' 42 | # get C:\Windows\System32\cmd.exe version in playbook 43 | --- 44 | - name: Get acm instance version 45 | win_file_version: 46 | path: 'C:\Windows\System32\cmd.exe' 47 | register: exe_file_version 48 | 49 | - debug: 50 | msg: '{{ exe_file_version }}' 51 | 52 | ''' 53 | 54 | RETURN = """ 55 | win_file_version.path: 56 | description: file path 57 | returned: always 58 | type: string 59 | 60 | win_file_version.file_version: 61 | description: file version number. 62 | returned: no error 63 | type: string 64 | 65 | win_file_version.product_version: 66 | description: the version of the product this file is distributed with. 67 | returned: no error 68 | type: string 69 | 70 | win_file_version.file_major_part: 71 | description: the major part of the version number. 72 | returned: no error 73 | type: string 74 | 75 | win_file_version.file_minor_part: 76 | description: the minor part of the version number of the file. 77 | returned: no error 78 | type: string 79 | 80 | win_file_version.file_build_part: 81 | description: build number of the file. 82 | returned: no error 83 | type: string 84 | 85 | win_file_version.file_private_part: 86 | description: file private part number. 87 | returned: no error 88 | type: string 89 | 90 | """ 91 | -------------------------------------------------------------------------------- /windows/win_firewall_rule.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # (c) 2014, Timothy Vandenbrande 4 | # 5 | # This file is part of Ansible 6 | # 7 | # Ansible is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # Ansible is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with Ansible. If not, see . 19 | 20 | ANSIBLE_METADATA = {'status': ['preview'], 21 | 'supported_by': 'community', 22 | 'version': '1.0'} 23 | 24 | DOCUMENTATION = ''' 25 | --- 26 | module: win_firewall_rule 27 | version_added: "2.0" 28 | author: Timothy Vandenbrande 29 | short_description: Windows firewall automation 30 | description: 31 | - allows you to create/remove/update firewall rules 32 | options: 33 | enable: 34 | description: 35 | - is this firewall rule enabled or disabled 36 | default: true 37 | required: false 38 | state: 39 | description: 40 | - should this rule be added or removed 41 | default: "present" 42 | required: true 43 | choices: ['present', 'absent'] 44 | name: 45 | description: 46 | - the rules name 47 | default: null 48 | required: true 49 | direction: 50 | description: 51 | - is this rule for inbound or outbound trafic 52 | default: null 53 | required: true 54 | choices: ['in', 'out'] 55 | action: 56 | description: 57 | - what to do with the items this rule is for 58 | default: null 59 | required: true 60 | choices: ['allow', 'block', 'bypass'] 61 | description: 62 | description: 63 | - description for the firewall rule 64 | default: null 65 | required: false 66 | localip: 67 | description: 68 | - the local ip address this rule applies to 69 | default: 'any' 70 | required: false 71 | remoteip: 72 | description: 73 | - the remote ip address/range this rule applies to 74 | default: 'any' 75 | required: false 76 | localport: 77 | description: 78 | - the local port this rule applies to 79 | default: 'any' 80 | required: false 81 | remoteport: 82 | description: 83 | - the remote port this rule applies to 84 | default: 'any' 85 | required: false 86 | program: 87 | description: 88 | - the program this rule applies to 89 | default: null 90 | required: false 91 | service: 92 | description: 93 | - the service this rule applies to 94 | default: 'any' 95 | required: false 96 | protocol: 97 | description: 98 | - the protocol this rule applies to 99 | default: 'any' 100 | required: false 101 | profile: 102 | description: 103 | - the profile this rule applies to, e.g. Domain,Private,Public 104 | default: 'any' 105 | required: false 106 | force: 107 | description: 108 | - Enforces the change if a rule with different values exists 109 | default: false 110 | required: false 111 | 112 | 113 | ''' 114 | 115 | EXAMPLES = ''' 116 | - name: Firewall rule to allow smtp on TCP port 25 117 | action: win_firewall_rule 118 | args: 119 | name: smtp 120 | enable: yes 121 | state: present 122 | localport: 25 123 | action: allow 124 | direction: In 125 | protocol: TCP 126 | 127 | ''' 128 | -------------------------------------------------------------------------------- /windows/win_iis_virtualdirectory.ps1: -------------------------------------------------------------------------------- 1 | #!powershell 2 | # -*- coding: utf-8 -*- 3 | 4 | # (c) 2015, Henrik Wallström 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | 21 | # WANT_JSON 22 | # POWERSHELL_COMMON 23 | 24 | $params = Parse-Args $args; 25 | 26 | # Name parameter 27 | $name = Get-Attr $params "name" $FALSE; 28 | If ($name -eq $FALSE) { 29 | Fail-Json (New-Object psobject) "missing required argument: name"; 30 | } 31 | 32 | # Site 33 | $site = Get-Attr $params "site" $FALSE; 34 | If ($site -eq $FALSE) { 35 | Fail-Json (New-Object psobject) "missing required argument: site"; 36 | } 37 | 38 | # Application 39 | $application = Get-Attr $params "application" $FALSE; 40 | 41 | # State parameter 42 | $state = Get-Attr $params "state" "present"; 43 | If (($state -ne 'present') -and ($state -ne 'absent')) { 44 | Fail-Json $result "state is '$state'; must be 'present' or 'absent'" 45 | } 46 | 47 | # Path parameter 48 | $physical_path = Get-Attr $params "physical_path" $FALSE; 49 | 50 | # Ensure WebAdministration module is loaded 51 | if ((Get-Module "WebAdministration" -ErrorAction SilentlyContinue) -eq $null) { 52 | Import-Module WebAdministration 53 | } 54 | 55 | # Result 56 | $result = New-Object psobject @{ 57 | directory = New-Object psobject 58 | changed = $false 59 | }; 60 | 61 | # Construct path 62 | $directory_path = if($application) { 63 | "IIS:\Sites\$($site)\$($application)\$($name)" 64 | } else { 65 | "IIS:\Sites\$($site)\$($name)" 66 | } 67 | 68 | # Directory info 69 | $directory = if($application) { 70 | Get-WebVirtualDirectory -Site $site -Name $name -Application $application 71 | } else { 72 | Get-WebVirtualDirectory -Site $site -Name $name 73 | } 74 | 75 | try { 76 | # Add directory 77 | If(($state -eq 'present') -and (-not $directory)) { 78 | If ($physical_path -eq $FALSE) { 79 | Fail-Json (New-Object psobject) "missing required arguments: physical_path" 80 | } 81 | If (-not (Test-Path $physical_path)) { 82 | Fail-Json (New-Object psobject) "specified folder must already exist: physical_path" 83 | } 84 | 85 | $directory_parameters = New-Object psobject @{ 86 | Site = $site 87 | Name = $name 88 | PhysicalPath = $physical_path 89 | }; 90 | 91 | If ($application) { 92 | $directory_parameters.Application = $application 93 | } 94 | 95 | $directory = New-WebVirtualDirectory @directory_parameters -Force 96 | $result.changed = $true 97 | } 98 | 99 | # Remove directory 100 | If ($state -eq 'absent' -and $directory) { 101 | Remove-Item $directory_path 102 | $result.changed = $true 103 | } 104 | 105 | $directory = Get-WebVirtualDirectory -Site $site -Name $name 106 | If($directory) { 107 | 108 | # Change Physical Path if needed 109 | if($physical_path) { 110 | If (-not (Test-Path $physical_path)) { 111 | Fail-Json (New-Object psobject) "specified folder must already exist: physical_path" 112 | } 113 | 114 | $vdir_folder = Get-Item $directory.PhysicalPath 115 | $folder = Get-Item $physical_path 116 | If($folder.FullName -ne $vdir_folder.FullName) { 117 | Set-ItemProperty $directory_path -name physicalPath -value $physical_path 118 | $result.changed = $true 119 | } 120 | } 121 | } 122 | } catch { 123 | Fail-Json $result $_.Exception.Message 124 | } 125 | 126 | # Result 127 | $directory = Get-WebVirtualDirectory -Site $site -Name $name 128 | $result.directory = New-Object psobject @{ 129 | PhysicalPath = $directory.PhysicalPath 130 | } 131 | 132 | Exit-Json $result 133 | -------------------------------------------------------------------------------- /windows/win_iis_virtualdirectory.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # (c) 2015, Henrik Wallström 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | 21 | ANSIBLE_METADATA = {'status': ['preview'], 22 | 'supported_by': 'community', 23 | 'version': '1.0'} 24 | 25 | DOCUMENTATION = ''' 26 | --- 27 | module: win_iis_virtualdirectory 28 | version_added: "2.0" 29 | short_description: Configures a virtual directory in IIS. 30 | description: 31 | - Creates, Removes and configures a virtual directory in IIS. 32 | options: 33 | name: 34 | description: 35 | - The name of the virtual directory to create or remove 36 | required: true 37 | state: 38 | description: 39 | - Whether to add or remove the specified virtual directory 40 | choices: 41 | - absent 42 | - present 43 | required: false 44 | default: present 45 | site: 46 | description: 47 | - The site name under which the virtual directory is created or exists. 48 | required: true 49 | application: 50 | description: 51 | - The application under which the virtual directory is created or exists. 52 | required: false 53 | default: null 54 | physical_path: 55 | description: 56 | - The physical path to the folder in which the new virtual directory is created. The specified folder must already exist. 57 | required: false 58 | default: null 59 | author: Henrik Wallström 60 | ''' 61 | 62 | EXAMPLES = ''' 63 | # This creates a virtual directory if it doesn't exist. 64 | $ ansible -i hosts -m win_iis_virtualdirectory -a "name='somedirectory' site=somesite state=present physical_path=c:\\virtualdirectory\\some" host 65 | 66 | # This removes a virtual directory if it exists. 67 | $ ansible -i hosts -m win_iis_virtualdirectory -a "name='somedirectory' site=somesite state=absent" host 68 | 69 | # This creates a virtual directory on an application if it doesn't exist. 70 | $ ansible -i hosts -m win_iis_virtualdirectory -a "name='somedirectory' site=somesite application=someapp state=present physical_path=c:\\virtualdirectory\\some" host 71 | ''' 72 | -------------------------------------------------------------------------------- /windows/win_iis_webapplication.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # (c) 2015, Henrik Wallström 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | 21 | ANSIBLE_METADATA = {'status': ['preview'], 22 | 'supported_by': 'community', 23 | 'version': '1.0'} 24 | 25 | DOCUMENTATION = ''' 26 | --- 27 | module: win_iis_webapplication 28 | version_added: "2.0" 29 | short_description: Configures a IIS Web application. 30 | description: 31 | - Creates, Removes and configures a IIS Web applications 32 | options: 33 | name: 34 | description: 35 | - Name of the Web applicatio 36 | required: true 37 | default: null 38 | aliases: [] 39 | site: 40 | description: 41 | - Name of the site on which the application is created. 42 | required: true 43 | default: null 44 | aliases: [] 45 | state: 46 | description: 47 | - State of the web application 48 | choices: 49 | - present 50 | - absent 51 | required: false 52 | default: null 53 | aliases: [] 54 | physical_path: 55 | description: 56 | - The physical path on the remote host to use for the new applicatiojn. The specified folder must already exist. 57 | required: false 58 | default: null 59 | aliases: [] 60 | application_pool: 61 | description: 62 | - The application pool in which the new site executes. 63 | required: false 64 | default: null 65 | aliases: [] 66 | author: Henrik Wallström 67 | ''' 68 | 69 | EXAMPLES = ''' 70 | $ ansible -i hosts -m win_iis_webapplication -a "name=api site=acme physical_path=c:\\apps\\acme\\api" host 71 | 72 | ''' 73 | -------------------------------------------------------------------------------- /windows/win_iis_webapppool.ps1: -------------------------------------------------------------------------------- 1 | #!powershell 2 | 3 | # (c) 2015, Henrik Wallström 4 | # 5 | # This file is part of Ansible 6 | # 7 | # Ansible is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # Ansible is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with Ansible. If not, see . 19 | 20 | 21 | # WANT_JSON 22 | # POWERSHELL_COMMON 23 | 24 | $params = Parse-Args $args; 25 | 26 | # Name parameter 27 | $name = Get-Attr $params "name" $FALSE; 28 | If ($name -eq $FALSE) { 29 | Fail-Json (New-Object psobject) "missing required argument: name"; 30 | } 31 | 32 | # State parameter 33 | $state = Get-Attr $params "state" $FALSE; 34 | $valid_states = ('started', 'restarted', 'stopped', 'absent'); 35 | If (($state -Ne $FALSE) -And ($state -NotIn $valid_states)) { 36 | Fail-Json $result "state is '$state'; must be $($valid_states)" 37 | } 38 | 39 | # Attributes parameter - Pipe separated list of attributes where 40 | # keys and values are separated by comma (paramA:valyeA|paramB:valueB) 41 | $attributes = @{}; 42 | If (Get-Member -InputObject $params -Name attributes) { 43 | $params.attributes -split '\|' | foreach { 44 | $key, $value = $_ -split "\:"; 45 | $attributes.Add($key, $value); 46 | } 47 | } 48 | 49 | # Ensure WebAdministration module is loaded 50 | if ((Get-Module "WebAdministration" -ErrorAction SilentlyContinue) -eq $NULL){ 51 | Import-Module WebAdministration 52 | } 53 | 54 | # Result 55 | $result = New-Object psobject @{ 56 | changed = $FALSE 57 | attributes = $attributes 58 | }; 59 | 60 | # Get pool 61 | $pool = Get-Item IIS:\AppPools\$name 62 | 63 | try { 64 | # Add 65 | if (-not $pool -and $state -in ('started', 'stopped', 'restarted')) { 66 | New-WebAppPool $name 67 | $result.changed = $TRUE 68 | } 69 | 70 | # Remove 71 | if ($pool -and $state -eq 'absent') { 72 | Remove-WebAppPool $name 73 | $result.changed = $TRUE 74 | } 75 | 76 | $pool = Get-Item IIS:\AppPools\$name 77 | if($pool) { 78 | # Set properties 79 | $attributes.GetEnumerator() | foreach { 80 | $newParameter = $_; 81 | $currentParameter = Get-ItemProperty ("IIS:\AppPools\" + $name) $newParameter.Key 82 | if(-not $currentParameter -or ($currentParameter.Value -as [String]) -ne $newParameter.Value) { 83 | Set-ItemProperty ("IIS:\AppPools\" + $name) $newParameter.Key $newParameter.Value 84 | $result.changed = $TRUE 85 | } 86 | } 87 | 88 | # Set run state 89 | if (($state -eq 'stopped') -and ($pool.State -eq 'Started')) { 90 | Stop-WebAppPool -Name $name -ErrorAction Stop 91 | $result.changed = $TRUE 92 | } 93 | if ((($state -eq 'started') -and ($pool.State -eq 'Stopped'))) { 94 | Start-WebAppPool -Name $name -ErrorAction Stop 95 | $result.changed = $TRUE 96 | } 97 | if ($state -eq 'restarted') { 98 | switch ($pool.State) 99 | { 100 | 'Stopped' { Start-WebAppPool -Name $name -ErrorAction Stop } 101 | default { Restart-WebAppPool -Name $name -ErrorAction Stop } 102 | } 103 | $result.changed = $TRUE 104 | } 105 | } 106 | } catch { 107 | Fail-Json $result $_.Exception.Message 108 | } 109 | 110 | # Result 111 | $pool = Get-Item IIS:\AppPools\$name 112 | if ($pool) 113 | { 114 | $result.info = @{ 115 | name = $pool.Name 116 | state = $pool.State 117 | attributes = New-Object psobject @{} 118 | }; 119 | 120 | $pool.Attributes | ForEach { $result.info.attributes.Add($_.Name, $_.Value)}; 121 | } 122 | 123 | Exit-Json $result -------------------------------------------------------------------------------- /windows/win_iis_webapppool.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # (c) 2015, Henrik Wallström 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | 21 | 22 | ANSIBLE_METADATA = {'status': ['preview'], 23 | 'supported_by': 'community', 24 | 'version': '1.0'} 25 | 26 | DOCUMENTATION = ''' 27 | --- 28 | module: win_iis_webapppool 29 | version_added: "2.0" 30 | short_description: Configures a IIS Web Application Pool. 31 | description: 32 | - Creates, Removes and configures a IIS Web Application Pool 33 | options: 34 | name: 35 | description: 36 | - Names of application pool 37 | required: true 38 | default: null 39 | aliases: [] 40 | state: 41 | description: 42 | - State of the binding 43 | choices: 44 | - absent 45 | - stopped 46 | - started 47 | - restarted 48 | required: false 49 | default: null 50 | aliases: [] 51 | attributes: 52 | description: 53 | - Application Pool attributes from string where attributes are seperated by a pipe and attribute name/values by colon Ex. "foo:1|bar:2" 54 | required: false 55 | default: null 56 | aliases: [] 57 | author: Henrik Wallström 58 | ''' 59 | 60 | EXAMPLES = ''' 61 | # This return information about an existing application pool 62 | $ansible -i inventory -m win_iis_webapppool -a "name='DefaultAppPool'" windows 63 | host | success >> { 64 | "attributes": {}, 65 | "changed": false, 66 | "info": { 67 | "attributes": { 68 | "CLRConfigFile": "", 69 | "applicationPoolSid": "S-1-5-82-3006700770-424185619-1745488364-794895919-4004696415", 70 | "autoStart": true, 71 | "enable32BitAppOnWin64": false, 72 | "enableConfigurationOverride": true, 73 | "managedPipelineMode": 0, 74 | "managedRuntimeLoader": "webengine4.dll", 75 | "managedRuntimeVersion": "v4.0", 76 | "name": "DefaultAppPool", 77 | "passAnonymousToken": true, 78 | "queueLength": 1000, 79 | "startMode": 0, 80 | "state": 1 81 | }, 82 | "name": "DefaultAppPool", 83 | "state": "Started" 84 | } 85 | } 86 | 87 | # This creates a new application pool in 'Started' state 88 | $ ansible -i inventory -m win_iis_webapppool -a "name='AppPool' state=started" windows 89 | 90 | # This stoppes an application pool 91 | $ ansible -i inventory -m win_iis_webapppool -a "name='AppPool' state=stopped" windows 92 | 93 | # This restarts an application pool 94 | $ ansible -i inventory -m win_iis_webapppool -a "name='AppPool' state=restart" windows 95 | 96 | # This restarts an application pool 97 | $ ansible -i inventory -m win_iis_webapppool -a "name='AppPool' state=restart" windows 98 | 99 | # This change application pool attributes without touching state 100 | $ ansible -i inventory -m win_iis_webapppool -a "name='AppPool' attributes='managedRuntimeVersion:v4.0|autoStart:false'" windows 101 | 102 | # This creates an application pool and sets attributes 103 | $ ansible -i inventory -m win_iis_webapppool -a "name='AnotherAppPool' state=started attributes='managedRuntimeVersion:v4.0|autoStart:false'" windows 104 | 105 | 106 | # Playbook example 107 | --- 108 | 109 | - name: App Pool with .NET 4.0 110 | win_iis_webapppool: 111 | name: 'AppPool' 112 | state: started 113 | attributes: managedRuntimeVersion:v4.0 114 | register: webapppool 115 | 116 | ''' 117 | -------------------------------------------------------------------------------- /windows/win_iis_webbinding.ps1: -------------------------------------------------------------------------------- 1 | #!powershell 2 | 3 | # (c) 2015, Henrik Wallström 4 | # 5 | # This file is part of Ansible 6 | # 7 | # Ansible is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # Ansible is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with Ansible. If not, see . 19 | 20 | 21 | # WANT_JSON 22 | # POWERSHELL_COMMON 23 | 24 | $params = Parse-Args $args; 25 | 26 | $name = Get-AnsibleParam $params -name "name" -failifempty $true 27 | $state = Get-AnsibleParam $params "state" -default "present" -validateSet "present","absent" 28 | $host_header = Get-AnsibleParam $params -name "host_header" 29 | $protocol = Get-AnsibleParam $params -name "protocol" 30 | $port = Get-AnsibleParam $params -name "port" 31 | $ip = Get-AnsibleParam $params -name "ip" 32 | $certificatehash = Get-AnsibleParam $params -name "certificate_hash" -default $false 33 | $certificateStoreName = Get-AnsibleParam $params -name "certificate_store_name" -default "MY" 34 | 35 | $binding_parameters = New-Object psobject @{ 36 | Name = $name 37 | }; 38 | 39 | If ($host_header) { 40 | $binding_parameters.HostHeader = $host_header 41 | } 42 | 43 | If ($protocol) { 44 | $binding_parameters.Protocol = $protocol 45 | } 46 | 47 | If ($port) { 48 | $binding_parameters.Port = $port 49 | } 50 | 51 | If ($ip) { 52 | $binding_parameters.IPAddress = $ip 53 | } 54 | 55 | # Ensure WebAdministration module is loaded 56 | if ((Get-Module "WebAdministration" -ErrorAction SilentlyContinue) -eq $null){ 57 | Import-Module WebAdministration 58 | } 59 | 60 | function Create-Binding-Info { 61 | return New-Object psobject @{ 62 | "bindingInformation" = $args[0].bindingInformation 63 | "certificateHash" = $args[0].certificateHash 64 | "certificateStoreName" = $args[0].certificateStoreName 65 | "isDsMapperEnabled" = $args[0].isDsMapperEnabled 66 | "protocol" = $args[0].protocol 67 | "sslFlags" = $args[0].sslFlags 68 | } 69 | } 70 | 71 | # Result 72 | $result = New-Object psobject @{ 73 | changed = $false 74 | parameters = $binding_parameters 75 | matched = @() 76 | removed = @() 77 | added = @() 78 | }; 79 | 80 | # Get bindings matching parameters 81 | $curent_bindings = Get-WebBinding @binding_parameters 82 | $curent_bindings | Foreach { 83 | $result.matched += Create-Binding-Info $_ 84 | } 85 | 86 | try { 87 | # Add 88 | if (-not $curent_bindings -and $state -eq 'present') { 89 | New-WebBinding @binding_parameters -Force 90 | 91 | # Select certificat 92 | if($certificateHash -ne $FALSE) { 93 | 94 | $ip = $binding_parameters["IPAddress"] 95 | if((!$ip) -or ($ip -eq "*")) { 96 | $ip = "0.0.0.0" 97 | } 98 | 99 | $port = $binding_parameters["Port"] 100 | if(!$port) { 101 | $port = 443 102 | } 103 | 104 | $result.port = $port 105 | $result.ip = $ip 106 | 107 | Push-Location IIS:\SslBindings\ 108 | Get-Item Cert:\LocalMachine\$certificateStoreName\$certificateHash | New-Item "$($ip)!$($port)" 109 | Pop-Location 110 | } 111 | 112 | $result.added += Create-Binding-Info (Get-WebBinding @binding_parameters) 113 | $result.changed = $true 114 | } 115 | 116 | # Remove 117 | if ($curent_bindings -and $state -eq 'absent') { 118 | $curent_bindings | foreach { 119 | Remove-WebBinding -InputObject $_ 120 | $result.removed += Create-Binding-Info $_ 121 | } 122 | $result.changed = $true 123 | } 124 | 125 | 126 | } 127 | catch { 128 | Fail-Json $result $_.Exception.Message 129 | } 130 | 131 | Exit-Json $result 132 | -------------------------------------------------------------------------------- /windows/win_owner.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # Copyright 2015, Hans-Joachim Kliemeck 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | 21 | # this is a windows documentation stub. actual code lives in the .ps1 22 | # file of the same name 23 | 24 | ANSIBLE_METADATA = {'status': ['preview'], 25 | 'supported_by': 'core', 26 | 'version': '1.0'} 27 | 28 | DOCUMENTATION = ''' 29 | --- 30 | module: win_owner 31 | version_added: "2.1" 32 | short_description: Set owner 33 | description: 34 | - Set owner of files or directories 35 | options: 36 | path: 37 | description: 38 | - Path to be used for changing owner 39 | required: true 40 | user: 41 | description: 42 | - Name to be used for changing owner 43 | required: true 44 | recurse: 45 | description: 46 | - Indicates if the owner should be changed recursively 47 | required: false 48 | choices: 49 | - no 50 | - yes 51 | default: no 52 | author: Hans-Joachim Kliemeck (@h0nIg) 53 | ''' 54 | 55 | EXAMPLES = ''' 56 | # Playbook example 57 | --- 58 | - name: Change owner of Path 59 | win_owner: 60 | path: 'C:\\apache\\' 61 | user: apache 62 | recurse: yes 63 | 64 | - name: Set the owner of root directory 65 | win_owner: 66 | path: 'C:\\apache\\' 67 | user: SYSTEM 68 | recurse: no 69 | ''' 70 | 71 | RETURN = ''' 72 | 73 | ''' -------------------------------------------------------------------------------- /windows/win_regmerge.ps1: -------------------------------------------------------------------------------- 1 | #!powershell 2 | # This file is part of Ansible 3 | # 4 | # Copyright 2015, Jon Hawkesworth (@jhawkesworth) 5 | # 6 | # Ansible is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Ansible is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with Ansible. If not, see . 18 | 19 | # WANT_JSON 20 | # POWERSHELL_COMMON 21 | 22 | Function Convert-RegistryPath { 23 | Param ( 24 | [parameter(Mandatory=$True)] 25 | [ValidateNotNullOrEmpty()]$Path 26 | ) 27 | 28 | $output = $Path -replace "HKLM:", "HKLM" 29 | $output = $output -replace "HKCU:", "HKCU" 30 | 31 | Return $output 32 | } 33 | 34 | $params = Parse-Args $args 35 | $result = New-Object PSObject 36 | Set-Attr $result "changed" $False 37 | 38 | $path = Get-Attr -obj $params -name path -failifempty $True -resultobj $result 39 | $compare_to = Get-Attr -obj $params -name compare_to -failifempty $False -resultobj $result 40 | 41 | # check it looks like a reg key, warn if key not present - will happen first time 42 | # only accepting PS-Drive style key names (starting with HKLM etc, not HKEY_LOCAL_MACHINE etc) 43 | 44 | $do_comparison = $False 45 | 46 | If ($compare_to) { 47 | $compare_to_key = $params.compare_to.ToString() 48 | If (Test-Path $compare_to_key -pathType container ) { 49 | $do_comparison = $True 50 | } Else { 51 | Set-Attr $result "compare_to_key_found" $False 52 | } 53 | } 54 | 55 | If ( $do_comparison -eq $True ) { 56 | $guid = [guid]::NewGuid() 57 | $exported_path = $env:TEMP + "\" + $guid.ToString() + 'ansible_win_regmerge.reg' 58 | 59 | $expanded_compare_key = Convert-RegistryPath ($compare_to_key) 60 | 61 | # export from the reg key location to a file 62 | $reg_args = @("EXPORT", "$expanded_compare_key", $exported_path) 63 | & reg.exe $reg_args 64 | 65 | # compare the two files 66 | $comparison_result = Compare-Object -ReferenceObject $(Get-Content $path) -DifferenceObject $(Get-Content $exported_path) 67 | 68 | If (Get-Member -InputObject $comparison_result -Name "count" -MemberType Properties ) 69 | { 70 | # Something is different, actually do reg merge 71 | $reg_import_args = @("IMPORT", "$path") 72 | $ret = & reg.exe $reg_import_args 2>&1 73 | If ($LASTEXITCODE -eq 0) { 74 | Set-Attr $result "changed" $True 75 | Set-Attr $result "difference_count" $comparison_result.count 76 | } Else { 77 | Set-Attr $result "rc" $LASTEXITCODE 78 | Fail-Json $result "$ret" 79 | } 80 | } Else { 81 | Set-Attr $result "difference_count" 0 82 | } 83 | 84 | Remove-Item $exported_path 85 | Set-Attr $result "compared" $True 86 | 87 | } Else { 88 | # not comparing, merge and report changed 89 | $reg_import_args = @("IMPORT", "$path") 90 | $ret = & reg.exe $reg_import_args 2>&1 91 | If ( $LASTEXITCODE -eq 0 ) { 92 | Set-Attr $result "changed" $True 93 | Set-Attr $result "compared" $False 94 | } Else { 95 | Set-Attr $result "rc" $LASTEXITCODE 96 | Fail-Json $result "$ret" 97 | } 98 | } 99 | 100 | Exit-Json $result 101 | -------------------------------------------------------------------------------- /windows/win_regmerge.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # (c) 2015, Jon Hawkesworth (@jhawkesworth) 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | 21 | # this is a windows documentation stub. actual code lives in the .ps1 22 | # file of the same name 23 | 24 | ANSIBLE_METADATA = {'status': ['preview'], 25 | 'supported_by': 'community', 26 | 'version': '1.0'} 27 | 28 | DOCUMENTATION = ''' 29 | --- 30 | module: win_regmerge 31 | version_added: "2.1" 32 | short_description: Merges the contents of a registry file into the windows registry 33 | description: 34 | - Wraps the reg.exe command to import the contents of a registry file. 35 | - Suitable for use with registry files created using M(win_template). 36 | - Windows registry files have a specific format and must be constructed correctly with carriage return and line feed line endings otherwise they will not be merged. 37 | - Exported registry files often start with a Byte Order Mark which must be removed if the file is to templated using M(win_template). 38 | - Registry file format is described at U(https://support.microsoft.com/en-us/kb/310516) 39 | - See also M(win_template), M(win_regedit) 40 | options: 41 | path: 42 | description: 43 | - The full path including file name to the registry file on the remote machine to be merged 44 | required: true 45 | default: no default 46 | compare_key: 47 | description: 48 | - The parent key to use when comparing the contents of the registry to the contents of the file. Needs to be in HKLM or HKCU part of registry. Use a PS-Drive style path for example HKLM:\SOFTWARE not HKEY_LOCAL_MACHINE\SOFTWARE 49 | If not supplied, or the registry key is not found, no comparison will be made, and the module will report changed. 50 | required: false 51 | default: no default 52 | author: "Jon Hawkesworth (@jhawkesworth)" 53 | notes: 54 | - Organise your registry files so that they contain a single root registry 55 | key if you want to use the compare_to functionality. 56 | This module does not force registry settings to be in the state 57 | described in the file. If registry settings have been modified externally 58 | the module will merge the contents of the file but continue to report 59 | differences on subsequent runs. 60 | To force registry change, use M(win_regedit) with state=absent before 61 | using M(win_regmerge). 62 | ''' 63 | 64 | EXAMPLES = ''' 65 | # Merge in a registry file without comparing to current registry 66 | # Note that paths using / to separate are preferred as they require less special handling than \ 67 | win_regmerge: 68 | path: C:/autodeploy/myCompany-settings.reg 69 | # Compare and merge registry file 70 | win_regmerge: 71 | path: C:/autodeploy/myCompany-settings.reg 72 | compare_to: HKLM:\SOFTWARE\myCompany 73 | ''' 74 | 75 | RETURN = ''' 76 | compare_to_key_found: 77 | description: whether the parent registry key has been found for comparison 78 | returned: when comparison key not found in registry 79 | type: boolean 80 | sample: false 81 | difference_count: 82 | description: number of differences between the registry and the file 83 | returned: changed 84 | type: integer 85 | sample: 1 86 | compared: 87 | description: whether a comparison has taken place between the registry and the file 88 | returned: when a comparison key has been supplied and comparison has been attempted 89 | type: boolean 90 | sample: true 91 | ''' 92 | -------------------------------------------------------------------------------- /windows/win_say.ps1: -------------------------------------------------------------------------------- 1 | #!powershell 2 | # This file is part of Ansible 3 | # 4 | # Copyright 2016, Jon Hawkesworth (@jhawkesworth) 5 | # 6 | # Ansible is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Ansible is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with Ansible. If not, see . 18 | 19 | # WANT_JSON 20 | # POWERSHELL_COMMON 21 | 22 | $params = Parse-Args $args; 23 | $result = New-Object PSObject; 24 | $msg = Get-AnsibleParam -obj $params -name "msg" 25 | $msg_file = Get-AnsibleParam -obj $params -name "msg_file" 26 | $start_sound_path = Get-AnsibleParam -obj $params -name "start_sound_path" 27 | $end_sound_path = Get-AnsibleParam -obj $params -name "end_sound_path" 28 | $voice = Get-AnsibleParam -obj $params -name "voice" 29 | $speech_speed = Get-AnsibleParam -obj $params -name "speech_speed" 30 | $speed = 0 31 | $words = $null 32 | 33 | if ($speech_speed -ne $null) { 34 | try { 35 | $speed = [convert]::ToInt32($speech_speed, 10) 36 | } catch { 37 | Fail-Json $result "speech_speed needs to a integer in the range -10 to 10. The value $speech_speed could not be converted to an integer." 38 | 39 | } 40 | if ($speed -lt -10 -or $speed -gt 10) { 41 | Fail-Json $result "speech_speed needs to a integer in the range -10 to 10. The value $speech_speed is outside this range." 42 | } 43 | } 44 | 45 | 46 | if ($msg_file -ne $null -and $msg -ne $null ) { 47 | Fail-Json $result "Please specify either msg_file or msg parameters, not both" 48 | } 49 | 50 | if ($msg_file -eq $null -and $msg -eq $null -and $start_sound_path -eq $null -and $end_sound_path -eq $null) { 51 | Fail-Json $result "No msg_file, msg, start_sound_path, or end_sound_path parameters have been specified. Please specify at least one so the module has something to do" 52 | 53 | } 54 | 55 | 56 | if ($msg_file -ne $null) { 57 | if (Test-Path $msg_file) { 58 | $words = Get-Content $msg_file | Out-String 59 | } else { 60 | Fail-Json $result "Message file $msg_file could not be found or opened. Ensure you have specified the full path to the file, and the ansible windows user has permission to read the file." 61 | } 62 | } 63 | 64 | if ($start_sound_path -ne $null) { 65 | if (Test-Path $start_sound_path) { 66 | (new-object Media.SoundPlayer $start_sound_path).playSync(); 67 | } else { 68 | Fail-Json $result "Start sound file $start_sound_path could not be found or opened. Ensure you have specified the full path to the file, and the ansible windows user has permission to read the file." 69 | } 70 | } 71 | 72 | if ($msg -ne $null) { 73 | $words = $msg 74 | } 75 | 76 | if ($words -ne $null) { 77 | Add-Type -AssemblyName System.speech 78 | $tts = New-Object System.Speech.Synthesis.SpeechSynthesizer 79 | if ($voice -ne $null) { 80 | try { 81 | $tts.SelectVoice($voice) 82 | } catch [System.Management.Automation.MethodInvocationException] { 83 | Set-Attr $result "voice_info" "Could not load voice $voice, using system default voice." 84 | } 85 | } 86 | 87 | Set-Attr $result "voice" $tts.Voice.Name 88 | if ($speed -ne 0) { 89 | $tts.Rate = $speed 90 | } 91 | $tts.Speak($words) 92 | $tts.Dispose() 93 | } 94 | 95 | if ($end_sound_path -ne $null) { 96 | if (Test-Path $end_sound_path) { 97 | (new-object Media.SoundPlayer $end_sound_path).playSync(); 98 | } else { 99 | Fail-Json $result "End sound file $start_sound_path could not be found or opened. Ensure you have specified the full path to the file, and the ansible windows user has permission to read the file." 100 | } 101 | } 102 | 103 | Set-Attr $result "changed" $false; 104 | Set-Attr $result "message_text" $words; 105 | 106 | Exit-Json $result; 107 | -------------------------------------------------------------------------------- /windows/win_scheduled_task.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # This file is part of Ansible 4 | # 5 | # Ansible is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # Ansible is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Ansible. If not, see . 17 | 18 | # this is a windows documentation stub. actual code lives in the .ps1 19 | # file of the same name 20 | 21 | ANSIBLE_METADATA = {'status': ['preview'], 22 | 'supported_by': 'community', 23 | 'version': '1.0'} 24 | 25 | DOCUMENTATION = ''' 26 | --- 27 | module: win_scheduled_task 28 | version_added: "2.0" 29 | short_description: Manage scheduled tasks 30 | description: 31 | - Manage scheduled tasks 32 | notes: 33 | - This module requires Windows Server 2012 or later. 34 | options: 35 | name: 36 | description: 37 | - Name of the scheduled task 38 | required: true 39 | description: 40 | description: 41 | - The description for the scheduled task 42 | required: false 43 | enabled: 44 | description: 45 | - Enable/disable the task 46 | choices: 47 | - yes 48 | - no 49 | default: yes 50 | state: 51 | description: 52 | - State that the task should become 53 | required: true 54 | choices: 55 | - present 56 | - absent 57 | user: 58 | description: 59 | - User to run scheduled task as 60 | required: false 61 | execute: 62 | description: 63 | - Command the scheduled task should execute 64 | required: false 65 | argument: 66 | description: 67 | - Arguments to provide scheduled task action 68 | required: false 69 | frequency: 70 | description: 71 | - The frequency of the command, not idempotent 72 | required: false 73 | choices: 74 | - daily 75 | - weekly 76 | time: 77 | description: 78 | - Time to execute scheduled task, not idempotent 79 | required: false 80 | days_of_week: 81 | description: 82 | - Days of the week to run a weekly task, not idempotent 83 | required: false 84 | path: 85 | description: 86 | - Task folder in which this task will be stored 87 | default: '\' 88 | ''' 89 | 90 | EXAMPLES = ''' 91 | # Create a scheduled task to open a command prompt 92 | - win_scheduled_task: 93 | name: TaskName 94 | execute: cmd 95 | frequency: daily 96 | time: 9am 97 | description: open command prompt 98 | path: example 99 | enable: yes 100 | state: present 101 | user: SYSTEM 102 | ''' 103 | -------------------------------------------------------------------------------- /windows/win_share.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # Copyright 2015, Hans-Joachim Kliemeck 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | 21 | # this is a windows documentation stub. actual code lives in the .ps1 22 | # file of the same name 23 | 24 | ANSIBLE_METADATA = {'status': ['preview'], 25 | 'supported_by': 'core', 26 | 'version': '1.0'} 27 | 28 | DOCUMENTATION = ''' 29 | --- 30 | module: win_share 31 | version_added: "2.1" 32 | short_description: Manage Windows shares 33 | description: 34 | - Add, modify or remove Windows share and set share permissions. 35 | requirements: 36 | - Windows 8.1 / Windows 2012 or newer 37 | options: 38 | name: 39 | description: 40 | - Share name 41 | required: yes 42 | path: 43 | description: 44 | - Share directory 45 | required: yes 46 | state: 47 | description: 48 | - Specify whether to add C(present) or remove C(absent) the specified share 49 | required: no 50 | choices: 51 | - present 52 | - absent 53 | default: present 54 | description: 55 | description: 56 | - Share description 57 | required: no 58 | default: none 59 | list: 60 | description: 61 | - Specify whether to allow or deny file listing, in case user got no permission on share 62 | required: no 63 | choices: 64 | - yes 65 | - no 66 | default: none 67 | read: 68 | description: 69 | - Specify user list that should get read access on share, separated by comma. 70 | required: no 71 | default: none 72 | change: 73 | description: 74 | - Specify user list that should get read and write access on share, separated by comma. 75 | required: no 76 | default: none 77 | full: 78 | description: 79 | - Specify user list that should get full access on share, separated by comma. 80 | required: no 81 | default: none 82 | deny: 83 | description: 84 | - Specify user list that should get no access, regardless of implied access on share, separated by comma. 85 | required: no 86 | default: none 87 | author: Hans-Joachim Kliemeck (@h0nIg) 88 | ''' 89 | 90 | EXAMPLES = ''' 91 | # Playbook example 92 | # Add share and set permissions 93 | --- 94 | - name: Add secret share 95 | win_share: 96 | name: internal 97 | description: top secret share 98 | path: C:/shares/internal 99 | list: 'no' 100 | full: Administrators,CEO 101 | read: HR-Global 102 | deny: HR-External 103 | 104 | - name: Add public company share 105 | win_share: 106 | name: company 107 | description: top secret share 108 | path: C:/shares/company 109 | list: 'yes' 110 | full: Administrators,CEO 111 | read: Global 112 | 113 | # Remove previously added share 114 | win_share: 115 | name: internal 116 | state: absent 117 | ''' 118 | 119 | RETURN = ''' 120 | 121 | ''' -------------------------------------------------------------------------------- /windows/win_timezone.ps1: -------------------------------------------------------------------------------- 1 | #!powershell 2 | # This file is part of Ansible 3 | # 4 | # Copyright 2015, Phil Schwartz 5 | # 6 | # Ansible is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Ansible is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with Ansible. If not, see . 18 | 19 | # WANT_JSON 20 | # POWERSHELL_COMMON 21 | 22 | $params = Parse-Args $args; 23 | 24 | $result = New-Object psobject @{ 25 | win_timezone = New-Object psobject 26 | changed = $false 27 | } 28 | 29 | $timezone = Get-Attr -obj $params -name timezone -failifempty $true -resultobj $result 30 | 31 | Try { 32 | # Get the current timezone set 33 | $currentTZ = $(tzutil.exe /g) 34 | If ($LASTEXITCODE -ne 0) { Throw "An error occured when getting the current machine's timezone setting." } 35 | 36 | If ( $currentTZ -eq $timezone ) { 37 | Exit-Json $result "$timezone is already set on this machine" 38 | } 39 | Else { 40 | $tzExists = $false 41 | #Check that timezone can even be set (if it is listed from tzutil as an available timezone to the machine) 42 | $tzList = $(tzutil.exe /l) 43 | If ($LASTEXITCODE -ne 0) { Throw "An error occured when listing the available timezones." } 44 | ForEach ($tz in $tzList) { 45 | If ( $tz -eq $timezone ) { 46 | $tzExists = $true 47 | break 48 | } 49 | } 50 | 51 | If ( $tzExists ) { 52 | tzutil.exe /s "$timezone" 53 | If ($LASTEXITCODE -ne 0) { Throw "An error occured when setting the specified timezone with tzutil." } 54 | $newTZ = $(tzutil.exe /g) 55 | If ($LASTEXITCODE -ne 0) { Throw "An error occured when getting the current machine's timezone setting." } 56 | 57 | If ( $timezone -eq $newTZ ) { 58 | $result.changed = $true 59 | } 60 | } 61 | Else { 62 | Fail-Json $result "The specified timezone: $timezone isn't supported on the machine." 63 | } 64 | } 65 | } 66 | Catch { 67 | Fail-Json $result "Error setting timezone to: $timezone." 68 | } 69 | 70 | 71 | Exit-Json $result; -------------------------------------------------------------------------------- /windows/win_timezone.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # (c) 2015, Phil Schwartz 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | 21 | # this is a windows documentation stub. actual code lives in the .ps1 22 | # file of the same name 23 | 24 | ANSIBLE_METADATA = {'status': ['preview'], 25 | 'supported_by': 'community', 26 | 'version': '1.0'} 27 | 28 | DOCUMENTATION = ''' 29 | --- 30 | module: win_timezone 31 | version_added: "2.1" 32 | short_description: Sets Windows machine timezone 33 | description: 34 | - Sets machine time to the specified timezone, the module will check if the provided timezone is supported on the machine. 35 | options: 36 | timezone: 37 | description: 38 | - Timezone to set to. Example Central Standard Time 39 | required: true 40 | default: null 41 | aliases: [] 42 | 43 | author: Phil Schwartz 44 | ''' 45 | 46 | 47 | EXAMPLES = ''' 48 | # Set machine's timezone to Central Standard Time 49 | win_timezone: 50 | timezone: "Central Standard Time" 51 | ''' 52 | 53 | RETURN = '''# ''' 54 | -------------------------------------------------------------------------------- /windows/win_unzip.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # (c) 2015, Phil Schwartz 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | 21 | # this is a windows documentation stub. actual code lives in the .ps1 22 | # file of the same name 23 | 24 | ANSIBLE_METADATA = {'status': ['preview'], 25 | 'supported_by': 'community', 26 | 'version': '1.0'} 27 | 28 | DOCUMENTATION = ''' 29 | --- 30 | module: win_unzip 31 | version_added: "2.0" 32 | short_description: Unzips compressed files and archives on the Windows node 33 | description: 34 | - Unzips compressed files and archives. For extracting any compression types other than .zip, the PowerShellCommunityExtensions (PSCX) Module is required. This module (in conjunction with PSCX) has the ability to recursively unzip files within the src zip file provided and also functionality for many other compression types. If the destination directory does not exist, it will be created before unzipping the file. Specifying rm parameter will force removal of the src file after extraction. 35 | options: 36 | src: 37 | description: 38 | - File to be unzipped (provide absolute path) 39 | required: true 40 | dest: 41 | description: 42 | - Destination of zip file (provide absolute path of directory). If it does not exist, the directory will be created. 43 | required: true 44 | rm: 45 | description: 46 | - Remove the zip file, after unzipping 47 | required: no 48 | choices: 49 | - true 50 | - false 51 | - yes 52 | - no 53 | default: false 54 | recurse: 55 | description: 56 | - Recursively expand zipped files within the src file. 57 | required: no 58 | default: false 59 | choices: 60 | - true 61 | - false 62 | - yes 63 | - no 64 | creates: 65 | description: 66 | - If this file or directory exists the specified src will not be extracted. 67 | required: no 68 | default: null 69 | author: Phil Schwartz 70 | ''' 71 | 72 | EXAMPLES = r''' 73 | # This unzips a library that was downloaded with win_get_url, and removes the file after extraction 74 | $ ansible -i hosts -m win_unzip -a "src=C:\LibraryToUnzip.zip dest=C:\Lib rm=true" all 75 | # Playbook example 76 | 77 | # Simple unzip 78 | --- 79 | - name: Unzip a bz2 (BZip) file 80 | win_unzip: 81 | src: "C:\Users\Phil\Logs.bz2" 82 | dest: "C:\Users\Phil\OldLogs" 83 | creates: "C:\Users\Phil\OldLogs" 84 | 85 | # This playbook example unzips a .zip file and recursively decompresses the contained .gz files and removes all unneeded compressed files after completion. 86 | --- 87 | - name: Unzip ApplicationLogs.zip and decompress all GZipped log files 88 | hosts: all 89 | gather_facts: false 90 | tasks: 91 | - name: Recursively decompress GZ files in ApplicationLogs.zip 92 | win_unzip: 93 | src: C:\Downloads\ApplicationLogs.zip 94 | dest: C:\Application\Logs 95 | recurse: yes 96 | rm: true 97 | 98 | # Install PSCX to use for extracting a gz file 99 | - name: Grab PSCX msi 100 | win_get_url: 101 | url: 'http://download-codeplex.sec.s-msft.com/Download/Release?ProjectName=pscx&DownloadId=923562&FileTime=130585918034470000&Build=20959' 102 | dest: 'C:\pscx.msi' 103 | - name: Install PSCX 104 | win_msi: 105 | path: 'C:\pscx.msi' 106 | - name: Unzip gz log 107 | win_unzip: 108 | src: "C:\Logs\application-error-logs.gz" 109 | dest: "C:\ExtractedLogs\application-error-logs" 110 | ''' 111 | -------------------------------------------------------------------------------- /windows/win_uri.ps1: -------------------------------------------------------------------------------- 1 | #!powershell 2 | # This file is part of Ansible 3 | # 4 | # Copyright 2015, Corwin Brown 5 | # 6 | # Ansible is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Ansible is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with Ansible. If not, see . 18 | 19 | # WANT_JSON 20 | # POWERSHELL_COMMON 21 | 22 | $params = Parse-Args $args; 23 | 24 | $result = New-Object psobject @{ 25 | win_uri = New-Object psobject 26 | } 27 | 28 | # Functions ############################################### 29 | 30 | Function ConvertTo-SnakeCase($input_string) { 31 | $snake_case = $input_string -csplit "(? 5 | # 6 | # Ansible is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Ansible is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with Ansible. If not, see . 18 | 19 | $ErrorActionPreference = "Stop" 20 | 21 | # WANT_JSON 22 | # POWERSHELL_COMMON 23 | 24 | $params = Parse-Args $args; 25 | $result = New-Object PSObject; 26 | Set-Attr $result "changed" $false; 27 | 28 | $package = Get-AnsibleParam $params -name "name" -failifempty $true 29 | 30 | Function Find-Command 31 | { 32 | [CmdletBinding()] 33 | param( 34 | [Parameter(Mandatory=$true, Position=0)] [string] $command 35 | ) 36 | $installed = get-command $command -erroraction Ignore 37 | write-verbose "$installed" 38 | if ($installed) 39 | { 40 | return $installed 41 | } 42 | return $null 43 | } 44 | 45 | Function Find-WebPiCmd 46 | { 47 | [CmdletBinding()] 48 | param() 49 | $p = Find-Command "webpicmd.exe" 50 | if ($p -ne $null) 51 | { 52 | return $p 53 | } 54 | $a = Find-Command "c:\programdata\chocolatey\bin\webpicmd.exe" 55 | if ($a -ne $null) 56 | { 57 | return $a 58 | } 59 | Throw "webpicmd.exe is not installed. It must be installed (use chocolatey)" 60 | } 61 | 62 | Function Test-IsInstalledFromWebPI 63 | { 64 | [CmdletBinding()] 65 | 66 | param( 67 | [Parameter(Mandatory=$true, Position=0)] 68 | [string]$package 69 | ) 70 | 71 | $cmd = "$executable /list /listoption:installed" 72 | $results = invoke-expression $cmd 73 | 74 | if ($LastExitCode -ne 0) 75 | { 76 | Set-Attr $result "webpicmd_error_cmd" $cmd 77 | Set-Attr $result "webpicmd_error_log" "$results" 78 | 79 | Throw "Error checking installation status for $package" 80 | } 81 | Write-Verbose "$results" 82 | 83 | if ($results -match "^$package\s+") 84 | { 85 | return $true 86 | } 87 | 88 | return $false 89 | } 90 | 91 | Function Install-WithWebPICmd 92 | { 93 | [CmdletBinding()] 94 | 95 | param( 96 | [Parameter(Mandatory=$true, Position=0)] 97 | [string]$package 98 | ) 99 | 100 | $cmd = "$executable /install /products:$package /accepteula /suppressreboot" 101 | 102 | $results = invoke-expression $cmd 103 | 104 | if ($LastExitCode -ne 0) 105 | { 106 | Set-Attr $result "webpicmd_error_cmd" $cmd 107 | Set-Attr $result "webpicmd_error_log" "$results" 108 | Throw "Error installing $package" 109 | } 110 | 111 | write-verbose "$results" 112 | 113 | if ($results -match "Install of Products: SUCCESS") 114 | { 115 | $result.changed = $true 116 | } 117 | } 118 | 119 | Try 120 | { 121 | $script:executable = Find-WebPiCmd 122 | if ((Test-IsInstalledFromWebPI -package $package) -eq $false) 123 | { 124 | Install-WithWebPICmd -package $package 125 | } 126 | 127 | Exit-Json $result; 128 | } 129 | Catch 130 | { 131 | Fail-Json $result $_.Exception.Message 132 | } 133 | -------------------------------------------------------------------------------- /windows/win_webpicmd.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # (c) 2015, Peter Mounce 5 | # 6 | # This file is part of Ansible 7 | # 8 | # Ansible is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # Ansible is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with Ansible. If not, see . 20 | 21 | # this is a windows documentation stub. actual code lives in the .ps1 22 | # file of the same name 23 | 24 | ANSIBLE_METADATA = {'status': ['preview'], 25 | 'supported_by': 'community', 26 | 'version': '1.0'} 27 | 28 | DOCUMENTATION = ''' 29 | --- 30 | module: win_webpicmd 31 | version_added: "2.0" 32 | short_description: Installs packages using Web Platform Installer command-line 33 | description: 34 | - Installs packages using Web Platform Installer command-line (http://www.iis.net/learn/install/web-platform-installer/web-platform-installer-v4-command-line-webpicmdexe-rtw-release). 35 | - Must be installed and present in PATH (see win_chocolatey module; 'webpicmd' is the package name, and you must install 'lessmsi' first too) 36 | - Install IIS first (see win_feature module) 37 | notes: 38 | - accepts EULAs and suppresses reboot - you will need to check manage reboots yourself (see win_reboot module) 39 | options: 40 | name: 41 | description: 42 | - Name of the package to be installed 43 | required: true 44 | author: Peter Mounce 45 | ''' 46 | 47 | EXAMPLES = ''' 48 | # Install URLRewrite2. 49 | win_webpicmd: 50 | name: URLRewrite2 51 | ''' 52 | --------------------------------------------------------------------------------