├── .github ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── README.md ├── cloud ├── __init__.py ├── amazon │ ├── __init__.py │ ├── _ec2_ami_search.py │ ├── cloudformation.py │ ├── ec2.py │ ├── ec2_ami.py │ ├── ec2_ami_find.py │ ├── ec2_asg.py │ ├── ec2_eip.py │ ├── ec2_elb.py │ ├── ec2_elb_lb.py │ ├── ec2_facts.py │ ├── ec2_group.py │ ├── ec2_key.py │ ├── ec2_lc.py │ ├── ec2_metric_alarm.py │ ├── ec2_scaling_policy.py │ ├── ec2_snapshot.py │ ├── ec2_tag.py │ ├── ec2_vol.py │ ├── ec2_vpc.py │ ├── ec2_vpc_net.py │ ├── elasticache.py │ ├── elasticache_subnet_group.py │ ├── iam.py │ ├── iam_cert.py │ ├── iam_policy.py │ ├── rds.py │ ├── rds_param_group.py │ ├── rds_subnet_group.py │ ├── route53.py │ └── s3.py ├── azure │ ├── __init__.py │ ├── azure.py │ ├── azure_rm_networkinterface.py │ ├── azure_rm_networkinterface_facts.py │ ├── azure_rm_publicipaddress.py │ ├── azure_rm_publicipaddress_facts.py │ ├── azure_rm_resourcegroup.py │ ├── azure_rm_resourcegroup_facts.py │ ├── azure_rm_securitygroup.py │ ├── azure_rm_securitygroup_facts.py │ ├── azure_rm_storageaccount.py │ ├── azure_rm_storageaccount_facts.py │ ├── azure_rm_storageblob.py │ ├── azure_rm_subnet.py │ ├── azure_rm_virtualmachine.py │ ├── azure_rm_virtualmachineimage_facts.py │ ├── azure_rm_virtualnetwork.py │ └── azure_rm_virtualnetwork_facts.py ├── digital_ocean │ ├── __init__.py │ ├── digital_ocean.py │ ├── digital_ocean_block_storage.py │ ├── digital_ocean_domain.py │ ├── digital_ocean_sshkey.py │ └── digital_ocean_tag.py ├── docker │ ├── __init__.py │ ├── _docker.py │ ├── docker_container.py │ ├── docker_image.py │ ├── docker_image_facts.py │ ├── docker_login.py │ ├── docker_network.py │ └── docker_service.py ├── google │ ├── __init__.py │ ├── gc_storage.py │ ├── gce.py │ ├── gce_lb.py │ ├── gce_mig.py │ ├── gce_net.py │ └── gce_pd.py ├── linode │ ├── __init__.py │ └── linode.py ├── openstack │ ├── README.md │ ├── __init__.py │ ├── _glance_image.py │ ├── _keystone_user.py │ ├── _nova_compute.py │ ├── _nova_keypair.py │ ├── _quantum_floating_ip.py │ ├── _quantum_floating_ip_associate.py │ ├── _quantum_network.py │ ├── _quantum_router.py │ ├── _quantum_router_gateway.py │ ├── _quantum_router_interface.py │ ├── _quantum_subnet.py │ ├── os_auth.py │ ├── os_client_config.py │ ├── os_floating_ip.py │ ├── os_image.py │ ├── os_image_facts.py │ ├── os_ironic.py │ ├── os_ironic_node.py │ ├── os_keypair.py │ ├── os_network.py │ ├── os_networks_facts.py │ ├── os_nova_flavor.py │ ├── os_object.py │ ├── os_port.py │ ├── os_router.py │ ├── os_security_group.py │ ├── os_security_group_rule.py │ ├── os_server.py │ ├── os_server_actions.py │ ├── os_server_facts.py │ ├── os_server_volume.py │ ├── os_subnet.py │ ├── os_subnets_facts.py │ ├── os_user.py │ ├── os_user_group.py │ └── os_volume.py ├── rackspace │ ├── __init__.py │ ├── rax.py │ ├── rax_cbs.py │ ├── rax_cbs_attachments.py │ ├── rax_cdb.py │ ├── rax_cdb_database.py │ ├── rax_cdb_user.py │ ├── rax_clb.py │ ├── rax_clb_nodes.py │ ├── rax_dns.py │ ├── rax_dns_record.py │ ├── rax_facts.py │ ├── rax_files.py │ ├── rax_files_objects.py │ ├── rax_identity.py │ ├── rax_keypair.py │ ├── rax_meta.py │ ├── rax_network.py │ ├── rax_queue.py │ ├── rax_scaling_group.py │ └── rax_scaling_policy.py └── vmware │ ├── __init__.py │ └── vsphere_guest.py ├── commands ├── __init__.py ├── command.py ├── raw.py ├── script.py └── shell.py ├── database ├── __init__.py ├── mysql │ ├── __init__.py │ ├── mysql_db.py │ ├── mysql_user.py │ └── mysql_variables.py └── postgresql │ ├── __init__.py │ ├── postgresql_db.py │ ├── postgresql_privs.py │ └── postgresql_user.py ├── files ├── __init__.py ├── acl.py ├── assemble.py ├── copy.py ├── fetch.py ├── file.py ├── find.py ├── ini_file.py ├── lineinfile.py ├── replace.py ├── stat.py ├── synchronize.py ├── template.py ├── unarchive.py └── xattr.py ├── inventory ├── __init__.py ├── add_host.py └── group_by.py ├── network ├── __init__.py ├── basics │ ├── __init__.py │ ├── get_url.py │ ├── slurp.py │ └── uri.py ├── cumulus │ ├── __init__.py │ ├── cl_bond.py │ ├── cl_bridge.py │ ├── cl_img_install.py │ ├── cl_interface.py │ ├── cl_interface_policy.py │ ├── cl_license.py │ └── cl_ports.py ├── dellos10 │ ├── __init__.py │ ├── dellos10_command.py │ ├── dellos10_config.py │ └── dellos10_facts.py ├── dellos6 │ ├── __init__.py │ ├── dellos6_command.py │ ├── dellos6_config.py │ └── dellos6_facts.py ├── dellos9 │ ├── __init__.py │ ├── dellos9_command.py │ ├── dellos9_config.py │ └── dellos9_facts.py ├── eos │ ├── __init__.py │ ├── _eos_template.py │ ├── eos_command.py │ ├── eos_config.py │ ├── eos_eapi.py │ └── eos_facts.py ├── ios │ ├── __init__.py │ ├── _ios_template.py │ ├── ios_command.py │ ├── ios_config.py │ └── ios_facts.py ├── iosxr │ ├── __init__.py │ ├── _iosxr_template.py │ ├── iosxr_command.py │ ├── iosxr_config.py │ └── iosxr_facts.py ├── junos │ ├── __init__.py │ ├── _junos_template.py │ ├── junos_command.py │ ├── junos_config.py │ ├── junos_facts.py │ ├── junos_netconf.py │ └── junos_package.py ├── netvisor │ ├── __init__.py │ ├── pn_cluster.py │ ├── pn_ospf.py │ ├── pn_ospfarea.py │ ├── pn_show.py │ ├── pn_trunk.py │ ├── pn_vlag.py │ ├── pn_vlan.py │ ├── pn_vrouter.py │ ├── pn_vrouterbgp.py │ ├── pn_vrouterif.py │ └── pn_vrouterlbif.py ├── nxos │ ├── __init__.py │ ├── _nxos_template.py │ ├── nxos_aaa_server.py │ ├── nxos_aaa_server_host.py │ ├── nxos_acl.py │ ├── nxos_acl_interface.py │ ├── nxos_bgp.py │ ├── nxos_bgp_af.py │ ├── nxos_bgp_neighbor.py │ ├── nxos_bgp_neighbor_af.py │ ├── nxos_command.py │ ├── nxos_config.py │ ├── nxos_evpn_global.py │ ├── nxos_evpn_vni.py │ ├── nxos_facts.py │ ├── nxos_feature.py │ ├── nxos_file_copy.py │ ├── nxos_gir.py │ ├── nxos_gir_profile_management.py │ ├── nxos_hsrp.py │ ├── nxos_igmp.py │ ├── nxos_igmp_interface.py │ ├── nxos_igmp_snooping.py │ ├── nxos_install_os.py │ ├── nxos_interface.py │ ├── nxos_interface_ospf.py │ ├── nxos_ip_interface.py │ ├── nxos_mtu.py │ ├── nxos_ntp.py │ ├── nxos_ntp_auth.py │ ├── nxos_ntp_options.py │ ├── nxos_nxapi.py │ ├── nxos_ospf.py │ ├── nxos_ospf_vrf.py │ ├── nxos_overlay_global.py │ ├── nxos_pim.py │ ├── nxos_pim_interface.py │ ├── nxos_pim_rp_address.py │ ├── nxos_ping.py │ ├── nxos_portchannel.py │ ├── nxos_reboot.py │ ├── nxos_rollback.py │ ├── nxos_smu.py │ ├── nxos_snapshot.py │ ├── nxos_snmp_community.py │ ├── nxos_snmp_contact.py │ ├── nxos_snmp_host.py │ ├── nxos_snmp_location.py │ ├── nxos_snmp_traps.py │ ├── nxos_snmp_user.py │ ├── nxos_static_route.py │ ├── nxos_switchport.py │ ├── nxos_udld.py │ ├── nxos_udld_interface.py │ ├── nxos_vlan.py │ ├── nxos_vpc.py │ ├── nxos_vpc_interface.py │ ├── nxos_vrf.py │ ├── nxos_vrf_af.py │ ├── nxos_vrf_interface.py │ ├── nxos_vrrp.py │ ├── nxos_vtp_domain.py │ ├── nxos_vtp_password.py │ ├── nxos_vtp_version.py │ ├── nxos_vxlan_vtep.py │ └── nxos_vxlan_vtep_vni.py ├── openswitch │ ├── __init__.py │ ├── _ops_template.py │ ├── ops_command.py │ ├── ops_config.py │ └── ops_facts.py ├── sros │ ├── __init__.py │ ├── sros_command.py │ ├── sros_config.py │ └── sros_rollback.py └── vyos │ ├── __init__.py │ ├── vyos_command.py │ ├── vyos_config.py │ └── vyos_facts.py ├── packaging ├── __init__.py ├── language │ ├── __init__.py │ ├── easy_install.py │ ├── gem.py │ └── pip.py └── os │ ├── __init__.py │ ├── apt.py │ ├── apt_key.py │ ├── apt_repository.py │ ├── apt_rpm.py │ ├── package.py │ ├── redhat_subscription.py │ ├── rhn_channel.py │ ├── rhn_register.py │ ├── rpm_key.py │ └── yum.py ├── source_control ├── __init__.py ├── git.py ├── hg.py └── subversion.py ├── system ├── __init__.py ├── authorized_key.py ├── cron.py ├── group.py ├── hostname.py ├── mount.py ├── ping.py ├── seboolean.py ├── selinux.py ├── service.py ├── setup.py ├── sysctl.py ├── systemd.py └── user.py ├── test └── utils │ └── shippable │ ├── ci.sh │ ├── docs-requirements.txt │ ├── docs.sh │ ├── integration.sh │ ├── sanity-skip-python24.txt │ └── sanity.sh ├── utilities ├── __init__.py ├── helper │ ├── __init__.py │ ├── _accelerate.py │ ├── _fireball.py │ └── meta.py └── logic │ ├── __init__.py │ ├── assert.py │ ├── async_status.py │ ├── async_wrapper.py │ ├── debug.py │ ├── fail.py │ ├── include.py │ ├── include_role.py │ ├── include_vars.py │ ├── pause.py │ ├── set_fact.py │ └── wait_for.py ├── web_infrastructure ├── __init__.py ├── apache2_module.py ├── django_manage.py ├── htpasswd.py └── supervisorctl.py └── windows ├── __init__.py ├── async_status.ps1 ├── async_wrapper.ps1 ├── setup.ps1 ├── slurp.ps1 ├── win_command.ps1 ├── win_command.py ├── win_copy.ps1 ├── win_copy.py ├── win_feature.ps1 ├── win_feature.py ├── win_file.ps1 ├── win_file.py ├── win_get_url.ps1 ├── win_get_url.py ├── win_group.ps1 ├── win_group.py ├── win_lineinfile.ps1 ├── win_lineinfile.py ├── win_msi.ps1 ├── win_msi.py ├── win_ping.ps1 ├── win_ping.py ├── win_reboot.py ├── win_service.ps1 ├── win_service.py ├── win_shell.ps1 ├── win_shell.py ├── win_stat.ps1 ├── win_stat.py ├── win_template.py ├── win_user.ps1 └── win_user.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-core/00911a75ad6635834b6d28eef41f197b2f73c381/cloud/__init__.py -------------------------------------------------------------------------------- /cloud/amazon/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/cloud/amazon/__init__.py -------------------------------------------------------------------------------- /cloud/azure/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/cloud/azure/__init__.py -------------------------------------------------------------------------------- /cloud/azure/azure_rm_resourcegroup_facts.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Copyright (c) 2016 Matt Davis, 4 | # Chris Houseknecht, 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': 'committer', 24 | 'version': '1.0'} 25 | 26 | DOCUMENTATION = ''' 27 | --- 28 | module: azure_rm_resouregroup_facts 29 | 30 | version_added: "2.1" 31 | 32 | short_description: Get resource group facts. 33 | 34 | description: 35 | - Get facts for a specific resource group or all resource groups. 36 | 37 | options: 38 | name: 39 | description: 40 | - Limit results to a specific resource group. 41 | required: false 42 | default: null 43 | tags: 44 | description: 45 | - Limit results by providing a list of tags. Format tags as 'key' or 'key:value'. 46 | required: false 47 | default: null 48 | 49 | extends_documentation_fragment: 50 | - azure 51 | 52 | author: 53 | - "Chris Houseknecht (@chouseknecht)" 54 | - "Matt Davis (@nitzmahone)" 55 | 56 | ''' 57 | 58 | EXAMPLES = ''' 59 | - name: Get facts for one resource group 60 | azure_rm_resourcegroup_facts: 61 | name: Testing 62 | 63 | - name: Get facts for all resource groups 64 | azure_rm_securitygroup_facts: 65 | 66 | - name: Get facts by tags 67 | azure_rm_resourcegroup_facts: 68 | tags: 69 | - testing 70 | - foo:bar 71 | ''' 72 | RETURN = ''' 73 | azure_resourcegroups: 74 | description: List of resource group dicts. 75 | returned: always 76 | type: list 77 | example: [{ 78 | "id": "/subscriptions/XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX/resourceGroups/Testing", 79 | "location": "westus", 80 | "name": "Testing", 81 | "properties": { 82 | "provisioningState": "Succeeded" 83 | }, 84 | "tags": { 85 | "delete": "never", 86 | "testing": "testing" 87 | } 88 | }] 89 | ''' 90 | 91 | from ansible.module_utils.basic import * 92 | from ansible.module_utils.azure_rm_common import * 93 | 94 | try: 95 | from msrestazure.azure_exceptions import CloudError 96 | from azure.common import AzureMissingResourceHttpError, AzureHttpError 97 | except: 98 | # This is handled in azure_rm_common 99 | pass 100 | 101 | 102 | AZURE_OBJECT_CLASS = 'ResourceGroup' 103 | 104 | 105 | class AzureRMResourceGroupFacts(AzureRMModuleBase): 106 | 107 | def __init__(self): 108 | 109 | self.module_arg_spec = dict( 110 | name=dict(type='str'), 111 | tags=dict(type='list') 112 | ) 113 | 114 | self.results = dict( 115 | changed=False, 116 | ansible_facts=dict(azure_resourcegroups=[]) 117 | ) 118 | 119 | self.name = None 120 | self.tags = None 121 | 122 | super(AzureRMResourceGroupFacts, self).__init__(self.module_arg_spec, 123 | supports_tags=False, 124 | facts_module=True) 125 | 126 | def exec_module(self, **kwargs): 127 | 128 | for key in self.module_arg_spec: 129 | setattr(self, key, kwargs[key]) 130 | 131 | if self.name: 132 | self.results['ansible_facts']['azure_resourcegroups'] = self.get_item() 133 | else: 134 | self.results['ansible_facts']['azure_resourcegroups'] = self.list_items() 135 | 136 | return self.results 137 | 138 | def get_item(self): 139 | self.log('Get properties for {0}'.format(self.name)) 140 | item = None 141 | result = [] 142 | 143 | try: 144 | item = self.rm_client.resource_groups.get(self.name) 145 | except CloudError: 146 | pass 147 | 148 | if item and self.has_tags(item.tags, self.tags): 149 | result = [self.serialize_obj(item, AZURE_OBJECT_CLASS)] 150 | 151 | return result 152 | 153 | def list_items(self): 154 | self.log('List all items') 155 | try: 156 | response = self.rm_client.resource_groups.list() 157 | except AzureHttpError as exc: 158 | self.fail("Failed to list all items - {1}".format(str(exc))) 159 | 160 | results = [] 161 | for item in response: 162 | if self.has_tags(item.tags, self.tags): 163 | results.append(self.serialize_obj(item, AZURE_OBJECT_CLASS)) 164 | return results 165 | 166 | 167 | def main(): 168 | AzureRMResourceGroupFacts() 169 | 170 | if __name__ == '__main__': 171 | main() 172 | 173 | -------------------------------------------------------------------------------- /cloud/digital_ocean/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/cloud/digital_ocean/__init__.py -------------------------------------------------------------------------------- /cloud/docker/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/cloud/docker/__init__.py -------------------------------------------------------------------------------- /cloud/google/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/cloud/google/__init__.py -------------------------------------------------------------------------------- /cloud/linode/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/cloud/linode/__init__.py -------------------------------------------------------------------------------- /cloud/openstack/README.md: -------------------------------------------------------------------------------- 1 | OpenStack Ansible Modules 2 | ========================= 3 | 4 | These are a set of modules for interacting with OpenStack as either an admin 5 | or an end user. If the module does not begin with os_, it's either deprecated 6 | or soon to be. This document serves as developer coding guidelines for 7 | modules intended to be here. 8 | 9 | Naming 10 | ------ 11 | 12 | * All modules should start with os_ 13 | * If the module is one that a cloud consumer would expect to use, it should be 14 | named after the logical resource it manages. Thus, os\_server not os\_nova. 15 | The reasoning for this is that there are more than one resource that are 16 | managed by more than one service and which one manages it is a deployment 17 | detail. A good example of this are floating IPs, which can come from either 18 | Nova or Neutron, but which one they come from is immaterial to an end user. 19 | * If the module is one that a cloud admin would expect to use, it should be 20 | be named with the service and the resouce, such as os\_keystone\_domain. 21 | * If the module is one that a cloud admin and a cloud consumer could both use, 22 | the cloud consumer rules apply. 23 | 24 | Interface 25 | --------- 26 | 27 | * If the resource being managed has an id, it should be returned. 28 | * If the resource being managed has an associated object more complex than 29 | an id, it should also be returned. 30 | 31 | Interoperability 32 | ---------------- 33 | 34 | * It should be assumed that the cloud consumer does not know a bazillion 35 | details about the deployment choices their cloud provider made, and a best 36 | effort should be made to present one sane interface to the ansible user 37 | regardless of deployer insanity. 38 | * All modules should work appropriately against all existing known public 39 | OpenStack clouds. 40 | * It should be assumed that a user may have more than one cloud account that 41 | they wish to combine as part of a single ansible managed infrastructure. 42 | 43 | Libraries 44 | --------- 45 | 46 | * All modules should use openstack\_full\_argument\_spec to pick up the 47 | standard input such as auth and ssl support. 48 | * All modules should extends\_documentation\_fragment: openstack to go along 49 | with openstack\_full\_argument\_spec. 50 | * All complex cloud interaction or interoperability code should be housed in 51 | the [shade](http://git.openstack.org/cgit/openstack-infra/shade) library. 52 | * All OpenStack API interactions should happen via shade and not via 53 | OpenStack Client libraries. The OpenStack Client libraries do no have end 54 | users as a primary audience, they are for intra-server communication. The 55 | python-openstacksdk is the future there, and shade will migrate to it when 56 | its ready in a manner that is not noticable to ansible users. 57 | 58 | Testing 59 | ------- 60 | 61 | * Integration testing is currently done in OpenStack's CI system in 62 | http://git.openstack.org/cgit/openstack-infra/shade/tree/shade/tests/ansible 63 | * Testing in shade produces an obvious chicken-and-egg scenario. Work is under 64 | way to trigger from and report on PRs directly. 65 | -------------------------------------------------------------------------------- /cloud/openstack/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/cloud/openstack/__init__.py -------------------------------------------------------------------------------- /cloud/openstack/os_auth.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Copyright (c) 2015 Hewlett-Packard Development Company, L.P. 4 | # 5 | # This module 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 | # This software 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 this software. If not, see . 17 | 18 | try: 19 | import shade 20 | from shade import meta 21 | HAS_SHADE = True 22 | except ImportError: 23 | HAS_SHADE = False 24 | 25 | ANSIBLE_METADATA = {'status': ['preview'], 26 | 'supported_by': 'community', 27 | 'version': '1.0'} 28 | 29 | DOCUMENTATION = ''' 30 | --- 31 | module: os_auth 32 | short_description: Retrieve an auth token 33 | version_added: "2.0" 34 | author: "Monty Taylor (@emonty)" 35 | description: 36 | - Retrieve an auth token from an OpenStack Cloud 37 | requirements: 38 | - "python >= 2.6" 39 | - "shade" 40 | extends_documentation_fragment: openstack 41 | ''' 42 | 43 | EXAMPLES = ''' 44 | - name: Authenticate to the cloud and retrieve the service catalog 45 | os_auth: 46 | cloud: rax-dfw 47 | 48 | - name: Show service catalog 49 | debug: 50 | var: service_catalog 51 | ''' 52 | 53 | def main(): 54 | 55 | argument_spec = openstack_full_argument_spec() 56 | module_kwargs = openstack_module_kwargs() 57 | module = AnsibleModule(argument_spec, **module_kwargs) 58 | 59 | if not HAS_SHADE: 60 | module.fail_json(msg='shade is required for this module') 61 | 62 | try: 63 | cloud = shade.openstack_cloud(**module.params) 64 | module.exit_json( 65 | changed=False, 66 | ansible_facts=dict( 67 | auth_token=cloud.auth_token, 68 | service_catalog=cloud.service_catalog)) 69 | except shade.OpenStackCloudException as e: 70 | module.fail_json(msg=str(e)) 71 | 72 | # this is magic, see lib/ansible/module_common.py 73 | from ansible.module_utils.basic import * 74 | from ansible.module_utils.openstack import * 75 | if __name__ == '__main__': 76 | main() 77 | -------------------------------------------------------------------------------- /cloud/openstack/os_client_config.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Copyright (c) 2015 Hewlett-Packard Development Company, L.P. 4 | # 5 | # This module 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 | # This software 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 this software. If not, see . 17 | 18 | import os_client_config 19 | from os_client_config import exceptions 20 | 21 | ANSIBLE_METADATA = {'status': ['preview'], 22 | 'supported_by': 'community', 23 | 'version': '1.0'} 24 | 25 | DOCUMENTATION = ''' 26 | --- 27 | module: os_client_config 28 | short_description: Get OpenStack Client config 29 | description: 30 | - Get I(openstack) client config data from clouds.yaml or environment 31 | version_added: "2.0" 32 | notes: 33 | - Facts are placed in the C(openstack.clouds) variable. 34 | options: 35 | clouds: 36 | description: 37 | - List of clouds to limit the return list to. No value means return 38 | information on all configured clouds 39 | required: false 40 | default: [] 41 | requirements: [ os-client-config ] 42 | author: "Monty Taylor (@emonty)" 43 | ''' 44 | 45 | EXAMPLES = ''' 46 | - name: Get list of clouds that do not support security groups 47 | os_client_config: 48 | 49 | - debug: 50 | var: "{{ item }}" 51 | with_items: "{{ openstack.clouds | rejectattr('secgroup_source', 'none') | list }}" 52 | 53 | - name: Get the information back just about the mordred cloud 54 | os_client_config: 55 | clouds: 56 | - mordred 57 | ''' 58 | 59 | 60 | def main(): 61 | module = AnsibleModule(argument_spec=dict( 62 | clouds=dict(required=False, type='list', default=[]), 63 | )) 64 | p = module.params 65 | 66 | try: 67 | config = os_client_config.OpenStackConfig() 68 | clouds = [] 69 | for cloud in config.get_all_clouds(): 70 | if not p['clouds'] or cloud.name in p['clouds']: 71 | cloud.config['name'] = cloud.name 72 | clouds.append(cloud.config) 73 | module.exit_json(ansible_facts=dict(openstack=dict(clouds=clouds))) 74 | except exceptions.OpenStackConfigException as e: 75 | module.fail_json(msg=str(e)) 76 | 77 | # import module snippets 78 | from ansible.module_utils.basic import * 79 | 80 | if __name__ == "__main__": 81 | main() 82 | -------------------------------------------------------------------------------- /cloud/openstack/os_networks_facts.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Copyright (c) 2015 Hewlett-Packard Development Company, L.P. 4 | # 5 | # This module 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 | # This software 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 this software. If not, see . 17 | 18 | try: 19 | import shade 20 | HAS_SHADE = True 21 | except ImportError: 22 | HAS_SHADE = False 23 | 24 | ANSIBLE_METADATA = {'status': ['preview'], 25 | 'supported_by': 'community', 26 | 'version': '1.0'} 27 | 28 | DOCUMENTATION = ''' 29 | --- 30 | module: os_networks_facts 31 | short_description: Retrieve facts about one or more OpenStack networks. 32 | version_added: "2.0" 33 | author: "Davide Agnello (@dagnello)" 34 | description: 35 | - Retrieve facts about one or more networks from OpenStack. 36 | requirements: 37 | - "python >= 2.6" 38 | - "shade" 39 | options: 40 | name: 41 | description: 42 | - Name or ID of the Network 43 | required: false 44 | filters: 45 | description: 46 | - A dictionary of meta data to use for further filtering. Elements of 47 | this dictionary may be additional dictionaries. 48 | required: false 49 | extends_documentation_fragment: openstack 50 | ''' 51 | 52 | EXAMPLES = ''' 53 | - name: Gather facts about previously created networks 54 | os_networks_facts: 55 | auth: 56 | auth_url: https://your_api_url.com:9000/v2.0 57 | username: user 58 | password: password 59 | project_name: someproject 60 | 61 | - name: Show openstack networks 62 | debug: 63 | var: openstack_networks 64 | 65 | - name: Gather facts about a previously created network by name 66 | os_networks_facts: 67 | auth: 68 | auth_url: https://your_api_url.com:9000/v2.0 69 | username: user 70 | password: password 71 | project_name: someproject 72 | name: network1 73 | 74 | - name: Show openstack networks 75 | debug: 76 | var: openstack_networks 77 | 78 | - name: Gather facts about a previously created network with filter 79 | # Note: name and filters parameters are Not mutually exclusive 80 | os_networks_facts: 81 | auth: 82 | auth_url: https://your_api_url.com:9000/v2.0 83 | username: user 84 | password: password 85 | project_name: someproject 86 | filters: 87 | tenant_id: 55e2ce24b2a245b09f181bf025724cbe 88 | subnets: 89 | - 057d4bdf-6d4d-4728-bb0f-5ac45a6f7400 90 | - 443d4dc0-91d4-4998-b21c-357d10433483 91 | 92 | - name: Show openstack networks 93 | debug: 94 | var: openstack_networks 95 | ''' 96 | 97 | RETURN = ''' 98 | openstack_networks: 99 | description: has all the openstack facts about the networks 100 | returned: always, but can be null 101 | type: complex 102 | contains: 103 | id: 104 | description: Unique UUID. 105 | returned: success 106 | type: string 107 | name: 108 | description: Name given to the network. 109 | returned: success 110 | type: string 111 | status: 112 | description: Network status. 113 | returned: success 114 | type: string 115 | subnets: 116 | description: Subnet(s) included in this network. 117 | returned: success 118 | type: list of strings 119 | tenant_id: 120 | description: Tenant id associated with this network. 121 | returned: success 122 | type: string 123 | shared: 124 | description: Network shared flag. 125 | returned: success 126 | type: boolean 127 | ''' 128 | 129 | def main(): 130 | 131 | argument_spec = openstack_full_argument_spec( 132 | name=dict(required=False, default=None), 133 | filters=dict(required=False, type='dict', default=None) 134 | ) 135 | module = AnsibleModule(argument_spec) 136 | 137 | if not HAS_SHADE: 138 | module.fail_json(msg='shade is required for this module') 139 | 140 | try: 141 | cloud = shade.openstack_cloud(**module.params) 142 | networks = cloud.search_networks(module.params['name'], 143 | module.params['filters']) 144 | module.exit_json(changed=False, ansible_facts=dict( 145 | openstack_networks=networks)) 146 | 147 | except shade.OpenStackCloudException as e: 148 | module.fail_json(msg=str(e)) 149 | 150 | # this is magic, see lib/ansible/module_common.py 151 | from ansible.module_utils.basic import * 152 | from ansible.module_utils.openstack import * 153 | if __name__ == '__main__': 154 | main() 155 | -------------------------------------------------------------------------------- /cloud/openstack/os_object.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Copyright (c) 2015 Hewlett-Packard Development Company, L.P. 4 | # Copyright (c) 2013, Benno Joy 5 | # 6 | # This module 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 software 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 software. If not, see . 18 | 19 | try: 20 | import shade 21 | HAS_SHADE = True 22 | except ImportError: 23 | HAS_SHADE = False 24 | 25 | 26 | ANSIBLE_METADATA = {'status': ['preview'], 27 | 'supported_by': 'community', 28 | 'version': '1.0'} 29 | 30 | DOCUMENTATION = ''' 31 | --- 32 | module: os_object 33 | short_description: Create or Delete objects and containers from OpenStack 34 | version_added: "2.0" 35 | author: "Monty Taylor (@emonty)" 36 | extends_documentation_fragment: openstack 37 | description: 38 | - Create or Delete objects and containers from OpenStack 39 | options: 40 | container: 41 | description: 42 | - The name of the container in which to create the object 43 | required: true 44 | name: 45 | description: 46 | - Name to be give to the object. If omitted, operations will be on 47 | the entire container 48 | required: false 49 | filename: 50 | description: 51 | - Path to local file to be uploaded. 52 | required: false 53 | container_access: 54 | description: 55 | - desired container access level. 56 | required: false 57 | choices: ['private', 'public'] 58 | default: private 59 | state: 60 | description: 61 | - Should the resource be present or absent. 62 | choices: [present, absent] 63 | default: present 64 | ''' 65 | 66 | EXAMPLES = ''' 67 | - name: "Create a object named 'fstab' in the 'config' container" 68 | os_object: 69 | cloud: mordred 70 | state: present 71 | name: fstab 72 | container: config 73 | filename: /etc/fstab 74 | 75 | - name: Delete a container called config and all of its contents 76 | os_object: 77 | cloud: rax-iad 78 | state: absent 79 | container: config 80 | ''' 81 | 82 | 83 | def process_object( 84 | cloud_obj, container, name, filename, container_access, **kwargs): 85 | 86 | changed = False 87 | container_obj = cloud_obj.get_container(container) 88 | if kwargs['state'] == 'present': 89 | if not container_obj: 90 | container_obj = cloud_obj.create_container(container) 91 | changed = True 92 | if cloud_obj.get_container_access(container) != container_access: 93 | cloud_obj.set_container_access(container, container_access) 94 | changed = True 95 | if name: 96 | if cloud_obj.is_object_stale(container, name, filename): 97 | cloud_obj.create_object(container, name, filename) 98 | changed = True 99 | else: 100 | if container_obj: 101 | if name: 102 | if cloud_obj.get_object_metadata(container, name): 103 | cloud_obj.delete_object(container, name) 104 | changed= True 105 | else: 106 | cloud_obj.delete_container(container) 107 | changed= True 108 | return changed 109 | 110 | 111 | def main(): 112 | argument_spec = openstack_full_argument_spec( 113 | name=dict(required=False, default=None), 114 | container=dict(required=True), 115 | filename=dict(required=False, default=None), 116 | container_access=dict(default='private', choices=['private', 'public']), 117 | state=dict(default='present', choices=['absent', 'present']), 118 | ) 119 | module_kwargs = openstack_module_kwargs() 120 | module = AnsibleModule(argument_spec, **module_kwargs) 121 | 122 | if not HAS_SHADE: 123 | module.fail_json(msg='shade is required for this module') 124 | 125 | try: 126 | cloud = shade.openstack_cloud(**module.params) 127 | 128 | changed = process_object(cloud, **module.params) 129 | 130 | module.exit_json(changed=changed) 131 | except shade.OpenStackCloudException as e: 132 | module.fail_json(msg=str(e)) 133 | 134 | # this is magic, see lib/ansible/module_common.py 135 | from ansible.module_utils.basic import * 136 | from ansible.module_utils.openstack import * 137 | 138 | if __name__ == "__main__": 139 | main() 140 | -------------------------------------------------------------------------------- /cloud/openstack/os_security_group.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Copyright (c) 2015 Hewlett-Packard Development Company, L.P. 4 | # Copyright (c) 2013, Benno Joy 5 | # 6 | # This module 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 software 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 software. If not, see . 18 | 19 | try: 20 | import shade 21 | HAS_SHADE = True 22 | except ImportError: 23 | HAS_SHADE = False 24 | 25 | 26 | ANSIBLE_METADATA = {'status': ['preview'], 27 | 'supported_by': 'community', 28 | 'version': '1.0'} 29 | 30 | DOCUMENTATION = ''' 31 | --- 32 | module: os_security_group 33 | short_description: Add/Delete security groups from an OpenStack cloud. 34 | extends_documentation_fragment: openstack 35 | author: "Monty Taylor (@emonty)" 36 | version_added: "2.0" 37 | description: 38 | - Add or Remove security groups from an OpenStack cloud. 39 | options: 40 | name: 41 | description: 42 | - Name that has to be given to the security group. This module 43 | requires that security group names be unique. 44 | required: true 45 | description: 46 | description: 47 | - Long description of the purpose of the security group 48 | required: false 49 | default: None 50 | state: 51 | description: 52 | - Should the resource be present or absent. 53 | choices: [present, absent] 54 | default: present 55 | ''' 56 | 57 | EXAMPLES = ''' 58 | # Create a security group 59 | - os_security_group: 60 | cloud: mordred 61 | state: present 62 | name: foo 63 | description: security group for foo servers 64 | 65 | # Update the existing 'foo' security group description 66 | - os_security_group: 67 | cloud: mordred 68 | state: present 69 | name: foo 70 | description: updated description for the foo security group 71 | ''' 72 | 73 | 74 | def _needs_update(module, secgroup): 75 | """Check for differences in the updatable values. 76 | 77 | NOTE: We don't currently allow name updates. 78 | """ 79 | if secgroup['description'] != module.params['description']: 80 | return True 81 | return False 82 | 83 | 84 | def _system_state_change(module, secgroup): 85 | state = module.params['state'] 86 | if state == 'present': 87 | if not secgroup: 88 | return True 89 | return _needs_update(module, secgroup) 90 | if state == 'absent' and secgroup: 91 | return True 92 | return False 93 | 94 | 95 | def main(): 96 | argument_spec = openstack_full_argument_spec( 97 | name=dict(required=True), 98 | description=dict(default=''), 99 | state=dict(default='present', choices=['absent', 'present']), 100 | ) 101 | 102 | module_kwargs = openstack_module_kwargs() 103 | module = AnsibleModule(argument_spec, 104 | supports_check_mode=True, 105 | **module_kwargs) 106 | 107 | if not HAS_SHADE: 108 | module.fail_json(msg='shade is required for this module') 109 | 110 | name = module.params['name'] 111 | state = module.params['state'] 112 | description = module.params['description'] 113 | 114 | try: 115 | cloud = shade.openstack_cloud(**module.params) 116 | secgroup = cloud.get_security_group(name) 117 | 118 | if module.check_mode: 119 | module.exit_json(changed=_system_state_change(module, secgroup)) 120 | 121 | changed = False 122 | if state == 'present': 123 | if not secgroup: 124 | secgroup = cloud.create_security_group(name, description) 125 | changed = True 126 | else: 127 | if _needs_update(module, secgroup): 128 | secgroup = cloud.update_security_group( 129 | secgroup['id'], description=description) 130 | changed = True 131 | module.exit_json( 132 | changed=changed, id=secgroup['id'], secgroup=secgroup) 133 | 134 | if state == 'absent': 135 | if secgroup: 136 | cloud.delete_security_group(secgroup['id']) 137 | changed = True 138 | module.exit_json(changed=changed) 139 | 140 | except shade.OpenStackCloudException as e: 141 | module.fail_json(msg=str(e)) 142 | 143 | # this is magic, see lib/ansible/module_common.py 144 | from ansible.module_utils.basic import * 145 | from ansible.module_utils.openstack import * 146 | 147 | if __name__ == "__main__": 148 | main() 149 | -------------------------------------------------------------------------------- /cloud/openstack/os_server_facts.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Copyright (c) 2014 Hewlett-Packard Development Company, L.P. 4 | # 5 | # This module 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 | # This software 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 this software. If not, see . 17 | 18 | import fnmatch 19 | 20 | try: 21 | import shade 22 | from shade import meta 23 | HAS_SHADE = True 24 | except ImportError: 25 | HAS_SHADE = False 26 | 27 | ANSIBLE_METADATA = {'status': ['preview'], 28 | 'supported_by': 'community', 29 | 'version': '1.0'} 30 | 31 | DOCUMENTATION = ''' 32 | --- 33 | module: os_server_facts 34 | short_description: Retrieve facts about one or more compute instances 35 | version_added: "2.0" 36 | description: 37 | - Retrieve facts about server instances from OpenStack. 38 | notes: 39 | - This module creates a new top-level C(openstack_servers) fact, which 40 | contains a list of servers. 41 | requirements: 42 | - "python >= 2.6" 43 | - "shade" 44 | options: 45 | server: 46 | description: 47 | - restrict results to servers with names matching 48 | this glob expression (e.g., C). 49 | required: false 50 | default: None 51 | detailed: 52 | description: 53 | - when true, return additional detail about servers at the expense 54 | of additional API calls. 55 | required: false 56 | default: false 57 | extends_documentation_fragment: openstack 58 | ''' 59 | 60 | EXAMPLES = ''' 61 | # Gather facts about all servers named C: 62 | - os_server_facts: 63 | cloud: rax-dfw 64 | server: web* 65 | - debug: 66 | var: openstack_servers 67 | ''' 68 | 69 | 70 | def main(): 71 | 72 | argument_spec = openstack_full_argument_spec( 73 | server=dict(required=False), 74 | detailed=dict(required=False, type='bool'), 75 | ) 76 | module_kwargs = openstack_module_kwargs() 77 | module = AnsibleModule(argument_spec, **module_kwargs) 78 | 79 | if not HAS_SHADE: 80 | module.fail_json(msg='shade is required for this module') 81 | 82 | try: 83 | cloud = shade.openstack_cloud(**module.params) 84 | openstack_servers = cloud.list_servers( 85 | detailed=module.params['detailed']) 86 | 87 | if module.params['server']: 88 | # filter servers by name 89 | pattern = module.params['server'] 90 | openstack_servers = [server for server in openstack_servers 91 | if fnmatch.fnmatch(server['name'], pattern)] 92 | module.exit_json(changed=False, ansible_facts=dict( 93 | openstack_servers=openstack_servers)) 94 | 95 | except shade.OpenStackCloudException as e: 96 | module.fail_json(msg=str(e)) 97 | 98 | # this is magic, see lib/ansible/module_common.py 99 | from ansible.module_utils.basic import * 100 | from ansible.module_utils.openstack import * 101 | if __name__ == '__main__': 102 | main() 103 | -------------------------------------------------------------------------------- /cloud/openstack/os_user_group.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # Copyright (c) 2015 Hewlett-Packard Development Company, L.P. 3 | # 4 | # This module 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 | # This software 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 this software. If not, see . 16 | 17 | 18 | try: 19 | import shade 20 | HAS_SHADE = True 21 | except ImportError: 22 | HAS_SHADE = False 23 | 24 | ANSIBLE_METADATA = {'status': ['preview'], 25 | 'supported_by': 'community', 26 | 'version': '1.0'} 27 | 28 | DOCUMENTATION = ''' 29 | --- 30 | module: os_user_group 31 | short_description: Associate OpenStack Identity users and groups 32 | extends_documentation_fragment: openstack 33 | version_added: "2.0" 34 | author: "Monty Taylor (@emonty)" 35 | description: 36 | - Add and remove users from groups 37 | options: 38 | user: 39 | description: 40 | - Name or id for the user 41 | required: true 42 | group: 43 | description: 44 | - Name or id for the group. 45 | required: true 46 | state: 47 | description: 48 | - Should the user be present or absent in the group 49 | choices: [present, absent] 50 | default: present 51 | requirements: 52 | - "python >= 2.6" 53 | - "shade" 54 | ''' 55 | 56 | EXAMPLES = ''' 57 | # Add the demo user to the demo group 58 | - os_user_group: 59 | cloud: mycloud 60 | user: demo 61 | group: demo 62 | ''' 63 | 64 | 65 | def _system_state_change(state, in_group): 66 | if state == 'present' and not in_group: 67 | return True 68 | if state == 'absent' and in_group: 69 | return True 70 | return False 71 | 72 | def main(): 73 | argument_spec = openstack_full_argument_spec( 74 | user=dict(required=True), 75 | group=dict(required=True), 76 | state=dict(default='present', choices=['absent', 'present']), 77 | ) 78 | 79 | module_kwargs = openstack_module_kwargs() 80 | module = AnsibleModule(argument_spec, 81 | supports_check_mode=True, 82 | **module_kwargs) 83 | 84 | if not HAS_SHADE: 85 | module.fail_json(msg='shade is required for this module') 86 | 87 | user = module.params['user'] 88 | group = module.params['group'] 89 | state = module.params['state'] 90 | 91 | try: 92 | cloud = shade.operator_cloud(**module.params) 93 | 94 | in_group = cloud.is_user_in_group(user, group) 95 | 96 | if module.check_mode: 97 | module.exit_json(changed=_system_state_change(state, in_group)) 98 | 99 | changed = False 100 | if state == 'present': 101 | if not in_group: 102 | cloud.add_user_to_group(user, group) 103 | changed = True 104 | 105 | elif state == 'absent': 106 | if in_group: 107 | cloud.remove_user_from_group(user, group) 108 | changed=True 109 | 110 | module.exit_json(changed=changed) 111 | 112 | except shade.OpenStackCloudException as e: 113 | module.fail_json(msg=str(e), extra_data=e.extra_data) 114 | 115 | 116 | from ansible.module_utils.basic import * 117 | from ansible.module_utils.openstack import * 118 | 119 | if __name__ == '__main__': 120 | main() 121 | -------------------------------------------------------------------------------- /cloud/rackspace/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/cloud/rackspace/__init__.py -------------------------------------------------------------------------------- /cloud/rackspace/rax_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 | # This is a DOCUMENTATION stub specific to this module, it extends 18 | # a documentation fragment located in ansible.utils.module_docs_fragments 19 | ANSIBLE_METADATA = {'status': ['preview'], 20 | 'supported_by': 'community', 21 | 'version': '1.0'} 22 | 23 | DOCUMENTATION = ''' 24 | --- 25 | module: rax_facts 26 | short_description: Gather facts for Rackspace Cloud Servers 27 | description: 28 | - Gather facts for Rackspace Cloud Servers. 29 | version_added: "1.4" 30 | options: 31 | address: 32 | description: 33 | - Server IP address to retrieve facts for, will match any IP assigned to 34 | the server 35 | id: 36 | description: 37 | - Server ID to retrieve facts for 38 | name: 39 | description: 40 | - Server name to retrieve facts for 41 | default: null 42 | author: "Matt Martz (@sivel)" 43 | extends_documentation_fragment: rackspace.openstack 44 | ''' 45 | 46 | EXAMPLES = ''' 47 | - name: Gather info about servers 48 | hosts: all 49 | gather_facts: False 50 | tasks: 51 | - name: Get facts about servers 52 | local_action: 53 | module: rax_facts 54 | credentials: ~/.raxpub 55 | name: "{{ inventory_hostname }}" 56 | region: DFW 57 | - name: Map some facts 58 | set_fact: 59 | ansible_ssh_host: "{{ rax_accessipv4 }}" 60 | ''' 61 | 62 | try: 63 | import pyrax 64 | HAS_PYRAX = True 65 | except ImportError: 66 | HAS_PYRAX = False 67 | 68 | 69 | def rax_facts(module, address, name, server_id): 70 | changed = False 71 | 72 | cs = pyrax.cloudservers 73 | 74 | if cs is None: 75 | module.fail_json(msg='Failed to instantiate client. This ' 76 | 'typically indicates an invalid region or an ' 77 | 'incorrectly capitalized region name.') 78 | 79 | ansible_facts = {} 80 | 81 | search_opts = {} 82 | if name: 83 | search_opts = dict(name='^%s$' % name) 84 | try: 85 | servers = cs.servers.list(search_opts=search_opts) 86 | except Exception as e: 87 | module.fail_json(msg='%s' % e.message) 88 | elif address: 89 | servers = [] 90 | try: 91 | for server in cs.servers.list(): 92 | for addresses in server.networks.values(): 93 | if address in addresses: 94 | servers.append(server) 95 | break 96 | except Exception as e: 97 | module.fail_json(msg='%s' % e.message) 98 | elif server_id: 99 | servers = [] 100 | try: 101 | servers.append(cs.servers.get(server_id)) 102 | except Exception as e: 103 | pass 104 | 105 | servers[:] = [server for server in servers if server.status != "DELETED"] 106 | 107 | if len(servers) > 1: 108 | module.fail_json(msg='Multiple servers found matching provided ' 109 | 'search parameters') 110 | elif len(servers) == 1: 111 | ansible_facts = rax_to_dict(servers[0], 'server') 112 | 113 | module.exit_json(changed=changed, ansible_facts=ansible_facts) 114 | 115 | 116 | def main(): 117 | argument_spec = rax_argument_spec() 118 | argument_spec.update( 119 | dict( 120 | address=dict(), 121 | id=dict(), 122 | name=dict(), 123 | ) 124 | ) 125 | 126 | module = AnsibleModule( 127 | argument_spec=argument_spec, 128 | required_together=rax_required_together(), 129 | mutually_exclusive=[['address', 'id', 'name']], 130 | required_one_of=[['address', 'id', 'name']], 131 | ) 132 | 133 | if not HAS_PYRAX: 134 | module.fail_json(msg='pyrax is required for this module') 135 | 136 | address = module.params.get('address') 137 | server_id = module.params.get('id') 138 | name = module.params.get('name') 139 | 140 | setup_rax_module(module, pyrax) 141 | 142 | rax_facts(module, address, name, server_id) 143 | 144 | 145 | # import module snippets 146 | from ansible.module_utils.basic import * 147 | from ansible.module_utils.rax import * 148 | 149 | ### invoke the module 150 | 151 | if __name__ == '__main__': 152 | main() 153 | -------------------------------------------------------------------------------- /cloud/rackspace/rax_identity.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 | # This is a DOCUMENTATION stub specific to this module, it extends 18 | # a documentation fragment located in ansible.utils.module_docs_fragments 19 | ANSIBLE_METADATA = {'status': ['preview'], 20 | 'supported_by': 'community', 21 | 'version': '1.0'} 22 | 23 | DOCUMENTATION = ''' 24 | --- 25 | module: rax_identity 26 | short_description: Load Rackspace Cloud Identity 27 | description: 28 | - Verifies Rackspace Cloud credentials and returns identity information 29 | version_added: "1.5" 30 | options: 31 | state: 32 | description: 33 | - Indicate desired state of the resource 34 | choices: ['present', 'absent'] 35 | default: present 36 | required: false 37 | author: 38 | - "Christopher H. Laco (@claco)" 39 | - "Matt Martz (@sivel)" 40 | extends_documentation_fragment: rackspace.openstack 41 | ''' 42 | 43 | EXAMPLES = ''' 44 | - name: Load Rackspace Cloud Identity 45 | gather_facts: False 46 | hosts: local 47 | connection: local 48 | tasks: 49 | - name: Load Identity 50 | local_action: 51 | module: rax_identity 52 | credentials: ~/.raxpub 53 | region: DFW 54 | register: rackspace_identity 55 | ''' 56 | 57 | try: 58 | import pyrax 59 | HAS_PYRAX = True 60 | except ImportError: 61 | HAS_PYRAX = False 62 | 63 | 64 | def cloud_identity(module, state, identity): 65 | instance = dict( 66 | authenticated=identity.authenticated, 67 | credentials=identity._creds_file 68 | ) 69 | changed = False 70 | 71 | instance.update(rax_to_dict(identity)) 72 | instance['services'] = instance.get('services', {}).keys() 73 | 74 | if state == 'present': 75 | if not identity.authenticated: 76 | module.fail_json(msg='Credentials could not be verified!') 77 | 78 | module.exit_json(changed=changed, identity=instance) 79 | 80 | 81 | def main(): 82 | argument_spec = rax_argument_spec() 83 | argument_spec.update( 84 | dict( 85 | state=dict(default='present', choices=['present']) 86 | ) 87 | ) 88 | 89 | module = AnsibleModule( 90 | argument_spec=argument_spec, 91 | required_together=rax_required_together() 92 | ) 93 | 94 | if not HAS_PYRAX: 95 | module.fail_json(msg='pyrax is required for this module') 96 | 97 | state = module.params.get('state') 98 | 99 | setup_rax_module(module, pyrax) 100 | 101 | if not pyrax.identity: 102 | module.fail_json(msg='Failed to instantiate client. This ' 103 | 'typically indicates an invalid region or an ' 104 | 'incorrectly capitalized region name.') 105 | 106 | cloud_identity(module, state, pyrax.identity) 107 | 108 | # import module snippets 109 | from ansible.module_utils.basic import * 110 | from ansible.module_utils.rax import * 111 | 112 | # invoke the module 113 | 114 | if __name__ == '__main__': 115 | main() 116 | -------------------------------------------------------------------------------- /cloud/rackspace/rax_network.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 | # This is a DOCUMENTATION stub specific to this module, it extends 18 | # a documentation fragment located in ansible.utils.module_docs_fragments 19 | ANSIBLE_METADATA = {'status': ['preview'], 20 | 'supported_by': 'community', 21 | 'version': '1.0'} 22 | 23 | DOCUMENTATION = ''' 24 | --- 25 | module: rax_network 26 | short_description: create / delete an isolated network in Rackspace Public Cloud 27 | description: 28 | - creates / deletes a Rackspace Public Cloud isolated network. 29 | version_added: "1.4" 30 | options: 31 | state: 32 | description: 33 | - Indicate desired state of the resource 34 | choices: 35 | - present 36 | - absent 37 | default: present 38 | label: 39 | description: 40 | - Label (name) to give the network 41 | default: null 42 | cidr: 43 | description: 44 | - cidr of the network being created 45 | default: null 46 | author: 47 | - "Christopher H. Laco (@claco)" 48 | - "Jesse Keating (@j2sol)" 49 | extends_documentation_fragment: rackspace.openstack 50 | ''' 51 | 52 | EXAMPLES = ''' 53 | - name: Build an Isolated Network 54 | gather_facts: False 55 | 56 | tasks: 57 | - name: Network create request 58 | local_action: 59 | module: rax_network 60 | credentials: ~/.raxpub 61 | label: my-net 62 | cidr: 192.168.3.0/24 63 | state: present 64 | ''' 65 | 66 | try: 67 | import pyrax 68 | HAS_PYRAX = True 69 | except ImportError: 70 | HAS_PYRAX = False 71 | 72 | 73 | def cloud_network(module, state, label, cidr): 74 | changed = False 75 | network = None 76 | networks = [] 77 | 78 | if not pyrax.cloud_networks: 79 | module.fail_json(msg='Failed to instantiate client. This ' 80 | 'typically indicates an invalid region or an ' 81 | 'incorrectly capitalized region name.') 82 | 83 | if state == 'present': 84 | if not cidr: 85 | module.fail_json(msg='missing required arguments: cidr') 86 | 87 | try: 88 | network = pyrax.cloud_networks.find_network_by_label(label) 89 | except pyrax.exceptions.NetworkNotFound: 90 | try: 91 | network = pyrax.cloud_networks.create(label, cidr=cidr) 92 | changed = True 93 | except Exception as e: 94 | module.fail_json(msg='%s' % e.message) 95 | except Exception as e: 96 | module.fail_json(msg='%s' % e.message) 97 | 98 | elif state == 'absent': 99 | try: 100 | network = pyrax.cloud_networks.find_network_by_label(label) 101 | network.delete() 102 | changed = True 103 | except pyrax.exceptions.NetworkNotFound: 104 | pass 105 | except Exception as e: 106 | module.fail_json(msg='%s' % e.message) 107 | 108 | if network: 109 | instance = dict(id=network.id, 110 | label=network.label, 111 | cidr=network.cidr) 112 | networks.append(instance) 113 | 114 | module.exit_json(changed=changed, networks=networks) 115 | 116 | 117 | def main(): 118 | argument_spec = rax_argument_spec() 119 | argument_spec.update( 120 | dict( 121 | state=dict(default='present', 122 | choices=['present', 'absent']), 123 | label=dict(required=True), 124 | cidr=dict() 125 | ) 126 | ) 127 | 128 | module = AnsibleModule( 129 | argument_spec=argument_spec, 130 | required_together=rax_required_together(), 131 | ) 132 | 133 | if not HAS_PYRAX: 134 | module.fail_json(msg='pyrax is required for this module') 135 | 136 | state = module.params.get('state') 137 | label = module.params.get('label') 138 | cidr = module.params.get('cidr') 139 | 140 | setup_rax_module(module, pyrax) 141 | 142 | cloud_network(module, state, label, cidr) 143 | 144 | 145 | # import module snippets 146 | from ansible.module_utils.basic import * 147 | from ansible.module_utils.rax import * 148 | 149 | ### invoke the module 150 | 151 | if __name__ == '__main__': 152 | main() 153 | -------------------------------------------------------------------------------- /cloud/rackspace/rax_queue.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 | # This is a DOCUMENTATION stub specific to this module, it extends 18 | # a documentation fragment located in ansible.utils.module_docs_fragments 19 | ANSIBLE_METADATA = {'status': ['preview'], 20 | 'supported_by': 'community', 21 | 'version': '1.0'} 22 | 23 | DOCUMENTATION = ''' 24 | --- 25 | module: rax_queue 26 | short_description: create / delete a queue in Rackspace Public Cloud 27 | description: 28 | - creates / deletes a Rackspace Public Cloud queue. 29 | version_added: "1.5" 30 | options: 31 | name: 32 | description: 33 | - Name to give the queue 34 | default: null 35 | state: 36 | description: 37 | - Indicate desired state of the resource 38 | choices: 39 | - present 40 | - absent 41 | default: present 42 | author: 43 | - "Christopher H. Laco (@claco)" 44 | - "Matt Martz (@sivel)" 45 | extends_documentation_fragment: rackspace 46 | ''' 47 | 48 | EXAMPLES = ''' 49 | - name: Build a Queue 50 | gather_facts: False 51 | hosts: local 52 | connection: local 53 | tasks: 54 | - name: Queue create request 55 | local_action: 56 | module: rax_queue 57 | credentials: ~/.raxpub 58 | name: my-queue 59 | region: DFW 60 | state: present 61 | register: my_queue 62 | ''' 63 | 64 | try: 65 | import pyrax 66 | HAS_PYRAX = True 67 | except ImportError: 68 | HAS_PYRAX = False 69 | 70 | 71 | def cloud_queue(module, state, name): 72 | for arg in (state, name): 73 | if not arg: 74 | module.fail_json(msg='%s is required for rax_queue' % arg) 75 | 76 | changed = False 77 | queues = [] 78 | instance = {} 79 | 80 | cq = pyrax.queues 81 | if not cq: 82 | module.fail_json(msg='Failed to instantiate client. This ' 83 | 'typically indicates an invalid region or an ' 84 | 'incorrectly capitalized region name.') 85 | 86 | for queue in cq.list(): 87 | if name != queue.name: 88 | continue 89 | 90 | queues.append(queue) 91 | 92 | if len(queues) > 1: 93 | module.fail_json(msg='Multiple Queues were matched by name') 94 | 95 | if state == 'present': 96 | if not queues: 97 | try: 98 | queue = cq.create(name) 99 | changed = True 100 | except Exception as e: 101 | module.fail_json(msg='%s' % e.message) 102 | else: 103 | queue = queues[0] 104 | 105 | instance = dict(name=queue.name) 106 | result = dict(changed=changed, queue=instance) 107 | module.exit_json(**result) 108 | 109 | elif state == 'absent': 110 | if queues: 111 | queue = queues[0] 112 | try: 113 | queue.delete() 114 | changed = True 115 | except Exception as e: 116 | module.fail_json(msg='%s' % e.message) 117 | 118 | module.exit_json(changed=changed, queue=instance) 119 | 120 | 121 | def main(): 122 | argument_spec = rax_argument_spec() 123 | argument_spec.update( 124 | dict( 125 | name=dict(), 126 | state=dict(default='present', choices=['present', 'absent']), 127 | ) 128 | ) 129 | 130 | module = AnsibleModule( 131 | argument_spec=argument_spec, 132 | required_together=rax_required_together() 133 | ) 134 | 135 | if not HAS_PYRAX: 136 | module.fail_json(msg='pyrax is required for this module') 137 | 138 | name = module.params.get('name') 139 | state = module.params.get('state') 140 | 141 | setup_rax_module(module, pyrax) 142 | 143 | cloud_queue(module, state, name) 144 | 145 | 146 | # import module snippets 147 | from ansible.module_utils.basic import * 148 | from ansible.module_utils.rax import * 149 | 150 | ### invoke the module 151 | 152 | if __name__ == '__main__': 153 | main() 154 | -------------------------------------------------------------------------------- /cloud/vmware/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/cloud/vmware/__init__.py -------------------------------------------------------------------------------- /commands/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/commands/__init__.py -------------------------------------------------------------------------------- /commands/raw.py: -------------------------------------------------------------------------------- 1 | # this is a virtual module that is entirely implemented server side 2 | 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 | ANSIBLE_METADATA = {'status': ['stableinterface'], 19 | 'supported_by': 'core', 20 | 'version': '1.0'} 21 | 22 | DOCUMENTATION = ''' 23 | --- 24 | module: raw 25 | short_description: Executes a low-down and dirty SSH command 26 | version_added: historical 27 | options: 28 | free_form: 29 | description: 30 | - the raw module takes a free form command to run 31 | required: true 32 | executable: 33 | description: 34 | - change the shell used to execute the command. Should be an absolute path to the executable. 35 | - when using privilege escalation (C(become)), a default shell will be assigned if one is not provided 36 | as privilege escalation requires a shell. 37 | required: false 38 | version_added: "1.0" 39 | description: 40 | - Executes a low-down and dirty SSH command, not going through the module 41 | subsystem. This is useful and should only be done in two cases. The 42 | first case is installing C(python-simplejson) on older (Python 2.4 and 43 | before) hosts that need it as a dependency to run modules, since nearly 44 | all core modules require it. Another is speaking to any devices such as 45 | routers that do not have any Python installed. In any other case, using 46 | the M(shell) or M(command) module is much more appropriate. Arguments 47 | given to M(raw) are run directly through the configured remote shell. 48 | Standard output, error output and return code are returned when 49 | available. There is no change handler support for this module. 50 | - This module does not require python on the remote system, much like 51 | the M(script) module. 52 | notes: 53 | - "If using raw from a playbook, you may need to disable fact gathering 54 | using C(gather_facts: no) if you're using C(raw) to bootstrap python 55 | onto the machine." 56 | - If you want to execute a command securely and predictably, it may be 57 | better to use the M(command) or M(shell) modules instead. 58 | - the C(environment) keyword does not work with raw normally, it requires a shell 59 | which means it only works if C(executable) is set or using the module 60 | with privilege escalation (C(become)). 61 | author: 62 | - Ansible Core Team 63 | - Michael DeHaan 64 | ''' 65 | 66 | EXAMPLES = ''' 67 | # Bootstrap a legacy python 2.4 host 68 | - raw: yum -y install python-simplejson 69 | 70 | # Bootstrap a host without python2 installed 71 | - raw: dnf install -y python2 python2-dnf libselinux-python 72 | 73 | # Run a command that uses non-posix shell-isms (in this example /bin/sh 74 | # doesn't handle redirection and wildcards together but bash does) 75 | - raw: cat < /tmp/*txt 76 | args: 77 | executable: /bin/bash 78 | ''' 79 | -------------------------------------------------------------------------------- /commands/script.py: -------------------------------------------------------------------------------- 1 | # This file is part of Ansible 2 | # 3 | # Ansible is 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 | # Ansible 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 Ansible. If not, see . 15 | 16 | ANSIBLE_METADATA = {'status': ['stableinterface'], 17 | 'supported_by': 'core', 18 | 'version': '1.0'} 19 | 20 | DOCUMENTATION = """ 21 | --- 22 | module: script 23 | version_added: "0.9" 24 | short_description: Runs a local script on a remote node after transferring it 25 | description: 26 | - "The M(script) module takes the script name followed by a list of 27 | space-delimited arguments. " 28 | - "The local script at path will be transferred to the remote node and then executed. " 29 | - "The given script will be processed through the shell environment on the remote node. " 30 | - "This module does not require python on the remote system, much like 31 | the M(raw) module. " 32 | options: 33 | free_form: 34 | description: 35 | - path to the local script file followed by optional arguments. 36 | required: true 37 | default: null 38 | aliases: [] 39 | creates: 40 | description: 41 | - a filename, when it already exists, this step will B(not) be run. 42 | required: no 43 | default: null 44 | version_added: "1.5" 45 | removes: 46 | description: 47 | - a filename, when it does not exist, this step will B(not) be run. 48 | required: no 49 | default: null 50 | version_added: "1.5" 51 | notes: 52 | - It is usually preferable to write Ansible modules than pushing scripts. Convert your script to an Ansible module for bonus points! 53 | - The ssh connection plugin will force psuedo-tty allocation via -tt when scripts are executed. psuedo-ttys do not have a stderr channel and all stderr is sent to stdout. If you depend on separated stdout and stderr result keys, please switch to a copy+command set of tasks instead of using script. 54 | author: 55 | - Ansible Core Team 56 | - Michael DeHaan 57 | """ 58 | 59 | EXAMPLES = ''' 60 | # Example from Ansible Playbooks 61 | - script: /some/local/script.sh --some-arguments 1234 62 | 63 | # Run a script that creates a file, but only if the file is not yet created 64 | - script: /some/local/create_file.sh --some-arguments 1234 65 | args: 66 | creates: /the/created/file.txt 67 | 68 | # Run a script that removes a file, but only if the file is not yet removed 69 | - script: /some/local/remove_file.sh --some-arguments 1234 70 | args: 71 | removes: /the/removed/file.txt 72 | ''' 73 | -------------------------------------------------------------------------------- /database/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/database/__init__.py -------------------------------------------------------------------------------- /database/mysql/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/database/mysql/__init__.py -------------------------------------------------------------------------------- /database/postgresql/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/database/postgresql/__init__.py -------------------------------------------------------------------------------- /files/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/files/__init__.py -------------------------------------------------------------------------------- /files/fetch.py: -------------------------------------------------------------------------------- 1 | # this is a virtual module that is entirely implemented server side 2 | 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 | ANSIBLE_METADATA = {'status': ['stableinterface'], 19 | 'supported_by': 'core', 20 | 'version': '1.0'} 21 | 22 | DOCUMENTATION = ''' 23 | --- 24 | module: fetch 25 | short_description: Fetches a file from remote nodes 26 | description: 27 | - This module works like M(copy), but in reverse. It is used for fetching 28 | files from remote machines and storing them locally in a file tree, 29 | organized by hostname. Note that this module is written to transfer 30 | log files that might not be present, so a missing remote file won't 31 | be an error unless fail_on_missing is set to 'yes'. 32 | version_added: "0.2" 33 | options: 34 | src: 35 | description: 36 | - The file on the remote system to fetch. This I(must) be a file, not a 37 | directory. Recursive fetching may be supported in a later release. 38 | required: true 39 | default: null 40 | aliases: [] 41 | dest: 42 | description: 43 | - A directory to save the file into. For example, if the I(dest) 44 | directory is C(/backup) a I(src) file named C(/etc/profile) on host 45 | C(host.example.com), would be saved into 46 | C(/backup/host.example.com/etc/profile) 47 | required: true 48 | default: null 49 | fail_on_missing: 50 | version_added: "1.1" 51 | description: 52 | - When set to 'yes', the task will fail if the source file is missing. 53 | required: false 54 | choices: [ "yes", "no" ] 55 | default: "no" 56 | validate_checksum: 57 | version_added: "1.4" 58 | description: 59 | - Verify that the source and destination checksums match after the files are fetched. 60 | required: false 61 | choices: [ "yes", "no" ] 62 | default: "yes" 63 | aliases: [ "validate_md5" ] 64 | flat: 65 | version_added: "1.2" 66 | description: 67 | - Allows you to override the default behavior of appending 68 | hostname/path/to/file to the destination. If dest ends with '/', it 69 | will use the basename of the source file, similar to the copy module. 70 | Obviously this is only handy if the filenames are unique. 71 | requirements: [] 72 | author: 73 | - "Ansible Core Team" 74 | - "Michael DeHaan" 75 | notes: 76 | - When running fetch with C(become), the M(slurp) module will also be 77 | used to fetch the contents of the file for determining the remote 78 | checksum. This effectively doubles the transfer size, and 79 | depending on the file size can consume all available memory on the 80 | remote or local hosts causing a C(MemoryError). Due to this it is 81 | advisable to run this module without C(become) whenever possible. 82 | ''' 83 | 84 | EXAMPLES = ''' 85 | # Store file into /tmp/fetched/host.example.com/tmp/somefile 86 | - fetch: 87 | src: /tmp/somefile 88 | dest: /tmp/fetched 89 | 90 | # Specifying a path directly 91 | - fetch: 92 | src: /tmp/somefile 93 | dest: /tmp/prefix-{{ inventory_hostname }} 94 | flat: yes 95 | 96 | # Specifying a destination path 97 | - fetch: 98 | src: /tmp/uniquefile 99 | dest: /tmp/special/ 100 | flat: yes 101 | 102 | # Storing in a path relative to the playbook 103 | - fetch: 104 | src: /tmp/uniquefile 105 | dest: special/prefix-{{ inventory_hostname }} 106 | flat: yes 107 | ''' 108 | -------------------------------------------------------------------------------- /files/template.py: -------------------------------------------------------------------------------- 1 | # this is a virtual module that is entirely implemented server side 2 | 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 | ANSIBLE_METADATA = {'status': ['stableinterface'], 19 | 'supported_by': 'core', 20 | 'version': '1.0'} 21 | 22 | DOCUMENTATION = ''' 23 | --- 24 | module: template 25 | version_added: historical 26 | short_description: Templates a file out to a remote server. 27 | description: 28 | - Templates are processed by the Jinja2 templating language 29 | (U(http://jinja.pocoo.org/docs/)) - documentation on the template 30 | formatting can be found in the Template Designer Documentation 31 | (U(http://jinja.pocoo.org/docs/templates/)). 32 | - "Six additional variables can be used in templates: C(ansible_managed) 33 | (configurable via the C(defaults) section of C(ansible.cfg)) contains a string 34 | which can be used to describe the template name, host, modification time of the 35 | template file and the owner uid, C(template_host) contains the node name of 36 | the template's machine, C(template_uid) the owner, C(template_path) the 37 | absolute path of the template, C(template_fullpath) is the absolute path of the 38 | template, and C(template_run_date) is the date that the template was rendered. Note that including 39 | a string that uses a date in the template will result in the template being marked 'changed' 40 | each time." 41 | options: 42 | src: 43 | description: 44 | - Path of a Jinja2 formatted template on the Ansible controller. This can be a relative or absolute path. 45 | required: true 46 | dest: 47 | description: 48 | - Location to render the template to on the remote machine. 49 | required: true 50 | backup: 51 | description: 52 | - Create a backup file including the timestamp information so you can get 53 | the original file back if you somehow clobbered it incorrectly. 54 | required: false 55 | choices: [ "yes", "no" ] 56 | default: "no" 57 | force: 58 | description: 59 | - the default is C(yes), which will replace the remote file when contents 60 | are different than the source. If C(no), the file will only be transferred 61 | if the destination does not exist. 62 | required: false 63 | choices: [ "yes", "no" ] 64 | default: "yes" 65 | notes: 66 | - "Since Ansible version 0.9, templates are loaded with C(trim_blocks=True)." 67 | - "Also, you can override jinja2 settings by adding a special header to template file. 68 | i.e. C(#jinja2:variable_start_string:'[%' , variable_end_string:'%]', trim_blocks: False) 69 | which changes the variable interpolation markers to [% var %] instead of {{ var }}. 70 | This is the best way to prevent evaluation of things that look like, but should not be Jinja2. 71 | raw/endraw in Jinja2 will not work as you expect because templates in Ansible are recursively evaluated." 72 | 73 | 74 | author: 75 | - Ansible Core Team 76 | - Michael DeHaan 77 | extends_documentation_fragment: 78 | - files 79 | - validate 80 | ''' 81 | 82 | EXAMPLES = ''' 83 | # Example from Ansible Playbooks 84 | - template: 85 | src: /mytemplates/foo.j2 86 | dest: /etc/file.conf 87 | owner: bin 88 | group: wheel 89 | mode: 0644 90 | 91 | # The same example, but using symbolic modes equivalent to 0644 92 | - template: 93 | src: /mytemplates/foo.j2 94 | dest: /etc/file.conf 95 | owner: bin 96 | group: wheel 97 | mode: "u=rw,g=r,o=r" 98 | 99 | # Copy a new "sudoers" file into place, after passing validation with visudo 100 | - template: 101 | src: /mine/sudoers 102 | dest: /etc/sudoers 103 | validate: 'visudo -cf %s' 104 | ''' 105 | -------------------------------------------------------------------------------- /inventory/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/inventory/__init__.py -------------------------------------------------------------------------------- /inventory/add_host.py: -------------------------------------------------------------------------------- 1 | # -*- mode: python -*- 2 | 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 | ANSIBLE_METADATA = {'status': ['stableinterface'], 19 | 'supported_by': 'core', 20 | 'version': '1.0'} 21 | 22 | DOCUMENTATION = ''' 23 | --- 24 | module: add_host 25 | short_description: add a host (and alternatively a group) to the ansible-playbook in-memory inventory 26 | description: 27 | - Use variables to create new hosts and groups in inventory for use in later plays of the same playbook. 28 | Takes variables so you can define the new hosts more fully. 29 | version_added: "0.9" 30 | options: 31 | name: 32 | aliases: [ 'hostname', 'host' ] 33 | description: 34 | - The hostname/ip of the host to add to the inventory, can include a colon and a port number. 35 | required: true 36 | groups: 37 | aliases: [ 'groupname', 'group' ] 38 | description: 39 | - The groups to add the hostname to, comma separated. 40 | required: false 41 | notes: 42 | - This module bypasses the play host loop and only runs once for all the hosts in the play, if you need it 43 | to iterate use a with\_ directive. 44 | author: 45 | - "Ansible Core Team" 46 | - "Seth Vidal" 47 | ''' 48 | 49 | EXAMPLES = ''' 50 | # add host to group 'just_created' with variable foo=42 51 | - add_host: 52 | name: "{{ ip_from_ec2 }}" 53 | groups: just_created 54 | foo: 42 55 | 56 | # add a host with a non-standard port local to your machines 57 | - add_host: 58 | name: "{{ new_ip }}:{{ new_port }}" 59 | 60 | # add a host alias that we reach through a tunnel (Ansible <= 1.9) 61 | - add_host: 62 | hostname: "{{ new_ip }}" 63 | ansible_ssh_host: "{{ inventory_hostname }}" 64 | ansible_ssh_port: "{{ new_port }}" 65 | 66 | # add a host alias that we reach through a tunnel (Ansible >= 2.0) 67 | - add_host: 68 | hostname: "{{ new_ip }}" 69 | ansible_host: "{{ inventory_hostname }}" 70 | ansible_port: "{{ new_port }}" 71 | ''' 72 | -------------------------------------------------------------------------------- /inventory/group_by.py: -------------------------------------------------------------------------------- 1 | # -*- mode: python -*- 2 | 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 | ANSIBLE_METADATA = {'status': ['stableinterface'], 19 | 'supported_by': 'core', 20 | 'version': '1.0'} 21 | 22 | DOCUMENTATION = ''' 23 | --- 24 | module: group_by 25 | short_description: Create Ansible groups based on facts 26 | description: 27 | - Use facts to create ad-hoc groups that can be used later in a playbook. 28 | version_added: "0.9" 29 | options: 30 | key: 31 | description: 32 | - The variables whose values will be used as groups 33 | required: true 34 | author: "Jeroen Hoekx (@jhoekx)" 35 | notes: 36 | - Spaces in group names are converted to dashes '-'. 37 | ''' 38 | 39 | EXAMPLES = ''' 40 | # Create groups based on the machine architecture 41 | - group_by: 42 | key: machine_{{ ansible_machine }} 43 | 44 | # Create groups like 'kvm-host' 45 | - group_by: 46 | key: virt_{{ ansible_virtualization_type }}_{{ ansible_virtualization_role }} 47 | ''' 48 | -------------------------------------------------------------------------------- /network/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/network/__init__.py -------------------------------------------------------------------------------- /network/basics/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/network/basics/__init__.py -------------------------------------------------------------------------------- /network/basics/slurp.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 | ANSIBLE_METADATA = {'status': ['stableinterface'], 22 | 'supported_by': 'core', 23 | 'version': '1.0'} 24 | 25 | DOCUMENTATION = ''' 26 | --- 27 | module: slurp 28 | version_added: historical 29 | short_description: Slurps a file from remote nodes 30 | description: 31 | - This module works like M(fetch). It is used for fetching a base64- 32 | encoded blob containing the data in a remote file. 33 | options: 34 | src: 35 | description: 36 | - The file on the remote system to fetch. This I(must) be a file, not a 37 | directory. 38 | required: true 39 | default: null 40 | aliases: [] 41 | notes: 42 | - This module returns an 'in memory' base64 encoded version of the file, take into account that this will require at least twice the RAM as the original file size. 43 | - "See also: M(fetch)" 44 | requirements: [] 45 | author: 46 | - "Ansible Core Team" 47 | - "Michael DeHaan" 48 | ''' 49 | 50 | EXAMPLES = ''' 51 | ansible host -m slurp -a 'src=/tmp/xx' 52 | host | success >> { 53 | "content": "aGVsbG8gQW5zaWJsZSB3b3JsZAo=", 54 | "encoding": "base64" 55 | } 56 | ''' 57 | 58 | import base64 59 | 60 | def main(): 61 | module = AnsibleModule( 62 | argument_spec = dict( 63 | src = dict(required=True, aliases=['path'], type='path'), 64 | ), 65 | supports_check_mode=True 66 | ) 67 | source = module.params['src'] 68 | 69 | if not os.path.exists(source): 70 | module.fail_json(msg="file not found: %s" % source) 71 | if not os.access(source, os.R_OK): 72 | module.fail_json(msg="file is not readable: %s" % source) 73 | 74 | data = base64.b64encode(open(source, 'rb').read()) 75 | 76 | module.exit_json(content=data, source=source, encoding='base64') 77 | 78 | # import module snippets 79 | from ansible.module_utils.basic import * 80 | 81 | if __name__ == '__main__': 82 | main() 83 | 84 | -------------------------------------------------------------------------------- /network/cumulus/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/network/cumulus/__init__.py -------------------------------------------------------------------------------- /network/dellos10/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/network/dellos10/__init__.py -------------------------------------------------------------------------------- /network/dellos6/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/network/dellos6/__init__.py -------------------------------------------------------------------------------- /network/dellos9/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/network/dellos9/__init__.py -------------------------------------------------------------------------------- /network/eos/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/network/eos/__init__.py -------------------------------------------------------------------------------- /network/ios/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/network/ios/__init__.py -------------------------------------------------------------------------------- /network/iosxr/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/network/iosxr/__init__.py -------------------------------------------------------------------------------- /network/junos/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/network/junos/__init__.py -------------------------------------------------------------------------------- /network/junos/junos_facts.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 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 | 19 | ANSIBLE_METADATA = {'status': ['preview'], 20 | 'supported_by': 'community', 21 | 'version': '1.0'} 22 | 23 | DOCUMENTATION = """ 24 | --- 25 | module: junos_facts 26 | version_added: "2.1" 27 | author: "Peter Sprygada (@privateip)" 28 | short_description: Collect facts from remote device running Junos 29 | description: 30 | - Collects fact information from a remote device running the Junos 31 | operating system. By default, the module will collect basic fact 32 | information from the device to be included with the hostvars. 33 | Additional fact information can be collected based on the 34 | configured set of arguments. 35 | extends_documentation_fragment: junos 36 | options: 37 | config: 38 | description: 39 | - The C(config) argument instructs the fact module to collect 40 | the configuration from the remote device. The configuration 41 | is then included in return facts. By default, the configuration 42 | is returned as text. The C(config_format) can be used to return 43 | different Junos configuration formats. 44 | required: false 45 | default: null 46 | config_format: 47 | description: 48 | - The C(config_format) argument is used to specify the desired 49 | format of the configuration file. Devices support three 50 | configuration file formats. By default, the configuration 51 | from the device is returned as text. The other option xml. 52 | If the xml option is chosen, the configuration file is 53 | returned as both xml and json. 54 | required: false 55 | default: text 56 | choices: ['xml', 'text'] 57 | requirements: 58 | - junos-eznc 59 | notes: 60 | - This module requires the netconf system service be enabled on 61 | the remote device being managed 62 | """ 63 | 64 | EXAMPLES = """ 65 | # the required set of connection arguments have been purposely left off 66 | # the examples for brevity 67 | 68 | - name: collect default set of facts 69 | junos_facts: 70 | 71 | - name: collect default set of facts and configuration 72 | junos_facts: 73 | config: yes 74 | 75 | - name: collect default set of facts and configuration in text format 76 | junos_facts: 77 | config: yes 78 | config_format: text 79 | 80 | - name: collect default set of facts and configuration in XML and JSON format 81 | junos_facts: 82 | config: yes 83 | config_format: xml 84 | """ 85 | 86 | RETURN = """ 87 | ansible_facts: 88 | description: Returns the facts collect from the device 89 | returned: always 90 | type: dict 91 | """ 92 | import ansible.module_utils.junos 93 | 94 | from ansible.module_utils.network import NetworkModule 95 | from ansible.module_utils.junos import xml_to_string, xml_to_json 96 | 97 | def main(): 98 | """ Main entry point for AnsibleModule 99 | """ 100 | spec = dict( 101 | config=dict(type='bool'), 102 | config_format=dict(default='text', choices=['xml', 'text']), 103 | transport=dict(default='netconf', choices=['netconf']) 104 | ) 105 | 106 | module = NetworkModule(argument_spec=spec, 107 | supports_check_mode=True) 108 | 109 | result = dict(changed=False) 110 | 111 | facts = module.connection.get_facts() 112 | 113 | if '2RE' in facts: 114 | facts['has_2RE'] = facts['2RE'] 115 | del facts['2RE'] 116 | 117 | facts['version_info'] = dict(facts['version_info']) 118 | 119 | if module.params['config'] is True: 120 | config_format = module.params['config_format'] 121 | resp_config = module.config.get_config(config_format=config_format) 122 | 123 | if config_format in ['text']: 124 | facts['config'] = resp_config 125 | elif config_format == "xml": 126 | facts['config'] = xml_to_string(resp_config) 127 | facts['config_json'] = xml_to_json(resp_config) 128 | 129 | result['ansible_facts'] = facts 130 | module.exit_json(**result) 131 | 132 | 133 | if __name__ == '__main__': 134 | main() 135 | -------------------------------------------------------------------------------- /network/junos/junos_netconf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 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 | 19 | ANSIBLE_METADATA = {'status': ['preview'], 20 | 'supported_by': 'core', 21 | 'version': '1.0'} 22 | 23 | DOCUMENTATION = """ 24 | --- 25 | module: junos_netconf 26 | version_added: "2.1" 27 | author: "Peter Sprygada (@privateip)" 28 | short_description: Configures the Junos Netconf system service 29 | description: 30 | - This module provides an abstraction that enables and configures 31 | the netconf system service running on Junos devices. This module 32 | can be used to easily enable the Netconf API. Netconf provides 33 | a programmatic interface for working with configuration and state 34 | resources as defined in RFC 6242. 35 | extends_documentation_fragment: junos 36 | options: 37 | netconf_port: 38 | description: 39 | - This argument specifies the port the netconf service should 40 | listen on for SSH connections. The default port as defined 41 | in RFC 6242 is 830. 42 | required: false 43 | default: 830 44 | aliases: ['listens_on'] 45 | version_added: "2.2" 46 | state: 47 | description: 48 | - Specifies the state of the M(junos_netconf) resource on 49 | the remote device. If the I(state) argument is set to 50 | I(present) the netconf service will be configured. If the 51 | I(state) argument is set to I(absent) the netconf service 52 | will be removed from the configuration. 53 | required: false 54 | default: present 55 | choices: ['present', 'absent'] 56 | """ 57 | 58 | EXAMPLES = """ 59 | # Note: examples below use the following provider dict to handle 60 | # transport and authentication to the node. 61 | vars: 62 | cli: 63 | host: "{{ inventory_hostname }}" 64 | username: ansible 65 | password: Ansible 66 | transport: cli 67 | 68 | - name: enable netconf service on port 830 69 | junos_netconf: 70 | listens_on: 830 71 | state: present 72 | provider: "{{ cli }}" 73 | 74 | - name: disable netconf service 75 | junos_netconf: 76 | state: absent 77 | provider: "{{ cli }}" 78 | """ 79 | 80 | RETURN = """ 81 | commands: 82 | description: Returns the command sent to the remote device 83 | returned: when changed is True 84 | type: str 85 | sample: 'set system services netconf ssh port 830' 86 | """ 87 | import re 88 | 89 | import ansible.module_utils.junos 90 | 91 | from ansible.module_utils.basic import get_exception 92 | from ansible.module_utils.network import NetworkModule, NetworkError 93 | 94 | def parse_port(config): 95 | match = re.search(r'port (\d+)', config) 96 | if match: 97 | return int(match.group(1)) 98 | 99 | def get_instance(module): 100 | cmd = 'show configuration system services netconf' 101 | cfg = module.cli(cmd)[0] 102 | result = dict(state='absent') 103 | if cfg: 104 | result = dict(state='present') 105 | result['port'] = parse_port(cfg) 106 | return result 107 | 108 | def main(): 109 | """main entry point for module execution 110 | """ 111 | 112 | argument_spec = dict( 113 | netconf_port=dict(type='int', default=830, aliases=['listens_on']), 114 | state=dict(default='present', choices=['present', 'absent']), 115 | transport=dict(default='cli', choices=['cli']) 116 | ) 117 | 118 | module = NetworkModule(argument_spec=argument_spec, 119 | supports_check_mode=True) 120 | 121 | state = module.params['state'] 122 | port = module.params['netconf_port'] 123 | 124 | result = dict(changed=False) 125 | 126 | instance = get_instance(module) 127 | 128 | if state == 'present' and instance.get('state') == 'absent': 129 | commands = 'set system services netconf ssh port %s' % port 130 | elif state == 'present' and port != instance.get('port'): 131 | commands = 'set system services netconf ssh port %s' % port 132 | elif state == 'absent' and instance.get('state') == 'present': 133 | commands = 'delete system services netconf' 134 | else: 135 | commands = None 136 | 137 | if commands: 138 | if not module.check_mode: 139 | try: 140 | comment = 'configuration updated by junos_netconf' 141 | module.config(commands, comment=comment) 142 | except NetworkError: 143 | exc = get_exception() 144 | module.fail_json(msg=str(exc), **exc.kwargs) 145 | result['changed'] = True 146 | result['commands'] = commands 147 | 148 | module.exit_json(**result) 149 | 150 | 151 | if __name__ == '__main__': 152 | main() 153 | -------------------------------------------------------------------------------- /network/netvisor/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/network/netvisor/__init__.py -------------------------------------------------------------------------------- /network/nxos/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/network/nxos/__init__.py -------------------------------------------------------------------------------- /network/openswitch/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/network/openswitch/__init__.py -------------------------------------------------------------------------------- /network/sros/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/network/sros/__init__.py -------------------------------------------------------------------------------- /network/vyos/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/network/vyos/__init__.py -------------------------------------------------------------------------------- /packaging/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/packaging/__init__.py -------------------------------------------------------------------------------- /packaging/language/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/packaging/language/__init__.py -------------------------------------------------------------------------------- /packaging/os/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/packaging/os/__init__.py -------------------------------------------------------------------------------- /packaging/os/package.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # (c) 2015, Ansible, 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 | ANSIBLE_METADATA = {'status': ['stableinterface'], 23 | 'supported_by': 'core', 24 | 'version': '1.0'} 25 | 26 | DOCUMENTATION = ''' 27 | --- 28 | module: package 29 | version_added: 2.0 30 | author: 31 | - Ansible Inc 32 | maintainers: 33 | - Ansible Core Team 34 | short_description: Generic OS package manager 35 | description: 36 | - Installs, upgrade and removes packages using the underlying OS package manager. 37 | options: 38 | name: 39 | description: 40 | - "Package name, or package specifier with version, like C(name-1.0)." 41 | - "Be aware that packages are not always named the same and this module will not 'translate' them per distro." 42 | required: true 43 | state: 44 | description: 45 | - Whether to install (C(present), C(latest)), or remove (C(absent)) a package. 46 | required: true 47 | use: 48 | description: 49 | - The required package manager module to use (yum, apt, etc). The default 'auto' will use existing facts or try to autodetect it. 50 | - You should only use this field if the automatic selection is not working for some reason. 51 | required: false 52 | default: auto 53 | requirements: 54 | - Whatever is required for the package plugins specific for each system. 55 | notes: 56 | - This module actually calls the pertinent package modules for each system (apt, yum, etc). 57 | ''' 58 | EXAMPLES = ''' 59 | - name: install the latest version of ntpdate 60 | package: 61 | name: ntpdate 62 | state: latest 63 | 64 | # This uses a variable as this changes per distribution. 65 | - name: remove the apache package 66 | package: 67 | name: "{{ apache }}" 68 | state: absent 69 | ''' 70 | -------------------------------------------------------------------------------- /source_control/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/source_control/__init__.py -------------------------------------------------------------------------------- /system/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/system/__init__.py -------------------------------------------------------------------------------- /system/ping.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # (c) 2012, Michael DeHaan 5 | # (c) 2016, Toshio Kuratomi 6 | # 7 | # This file is part of Ansible 8 | # 9 | # Ansible is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # Ansible is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with Ansible. If not, see . 21 | 22 | 23 | ANSIBLE_METADATA = {'status': ['stableinterface'], 24 | 'supported_by': 'core', 25 | 'version': '1.0'} 26 | 27 | DOCUMENTATION = ''' 28 | --- 29 | module: ping 30 | version_added: historical 31 | short_description: Try to connect to host, verify a usable python and return C(pong) on success. 32 | description: 33 | - A trivial test module, this module always returns C(pong) on successful 34 | contact. It does not make sense in playbooks, but it is useful from 35 | C(/usr/bin/ansible) to verify the ability to login and that a usable python is configured. 36 | - This is NOT ICMP ping, this is just a trivial test module. 37 | options: {} 38 | author: 39 | - "Ansible Core Team" 40 | - "Michael DeHaan" 41 | ''' 42 | 43 | EXAMPLES = ''' 44 | # Test we can logon to 'webservers' and execute python with json lib. 45 | ansible webservers -m ping 46 | ''' 47 | 48 | from ansible.module_utils.basic import AnsibleModule 49 | 50 | def main(): 51 | module = AnsibleModule( 52 | argument_spec=dict( 53 | data=dict(required=False, default=None), 54 | ), 55 | supports_check_mode=True 56 | ) 57 | result = dict(ping='pong') 58 | if module.params['data']: 59 | if module.params['data'] == 'crash': 60 | raise Exception("boom") 61 | result['ping'] = module.params['data'] 62 | module.exit_json(**result) 63 | 64 | if __name__ == '__main__': 65 | main() 66 | 67 | -------------------------------------------------------------------------------- /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/[^/]+/(?!(ec2_facts.py|_ec2_ami_search.py)) 2 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /utilities/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/utilities/__init__.py -------------------------------------------------------------------------------- /utilities/helper/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/utilities/helper/__init__.py -------------------------------------------------------------------------------- /utilities/helper/_fireball.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 | ANSIBLE_METADATA = {'status': ['deprecated'], 22 | 'supported_by': 'community', 23 | 'version': '1.0'} 24 | 25 | DOCUMENTATION = ''' 26 | --- 27 | module: fireball 28 | short_description: Enable fireball mode on remote node 29 | version_added: "0.9" 30 | deprecated: "in favor of SSH with ControlPersist" 31 | description: 32 | - Modern SSH clients support ControlPersist which is just as fast as 33 | fireball was. Please enable that in ansible.cfg as a replacement 34 | for fireball. 35 | - Removed in ansible 2.0. 36 | author: 37 | - "Ansible Core Team" 38 | - "Michael DeHaan" 39 | ''' 40 | 41 | EXAMPLES = ''' 42 | ''' 43 | 44 | -------------------------------------------------------------------------------- /utilities/helper/meta.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # (c) 2016, Ansible, a Red Hat company 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': 'core', 23 | 'version': '1.0'} 24 | 25 | DOCUMENTATION = ''' 26 | module: meta 27 | short_description: Execute Ansible 'actions' 28 | version_added: "1.2" 29 | description: 30 | - Meta tasks are a special kind of task which can influence Ansible internal execution or state. Prior to Ansible 2.0, 31 | the only meta option available was `flush_handlers`. As of 2.2, there are five meta tasks which can be used. 32 | Meta tasks can be used anywhere within your playbook. 33 | options: 34 | free_form: 35 | description: 36 | - This module takes a free form command, as a string. There's not an actual option named "free form". See the examples! 37 | - "C(flush_handlers) makes Ansible run any handler tasks which have thus far been notified. Ansible inserts these tasks internally at certain points to implicitly trigger handler runs (after pre/post tasks, the final role execution, and the main tasks section of your plays)." 38 | - "C(refresh_inventory) (added in 2.0) forces the reload of the inventory, which in the case of dynamic inventory scripts means they will be re-executed. This is mainly useful when additional hosts are created and users wish to use them instead of using the `add_host` module." 39 | - "C(noop) (added in 2.0) This literally does 'nothing'. It is mainly used internally and not recommended for general use." 40 | - "C(clear_facts) (added in 2.1) causes the gathered facts for the hosts specified in the play's list of hosts to be cleared, including the fact cache." 41 | - "C(clear_host_errors) (added in 2.1) clears the failed state (if any) from hosts specified in the play's list of hosts." 42 | - "C(end_play) (added in 2.2) causes the play to end without failing the host." 43 | choices: ['noop', 'flush_handlers', 'refresh_inventory', 'clear_facts', 'clear_host_errors', 'end_play'] 44 | required: true 45 | default: null 46 | notes: 47 | - meta is not really a module nor action_plugin as such it cannot be overwritten. 48 | author: 49 | - "Ansible Core Team" 50 | ''' 51 | 52 | EXAMPLES = ''' 53 | # force all notified handlers to run at this point, not waiting for normal sync points 54 | - template: 55 | src: new.j2 56 | dest: /etc/config.txt 57 | notify: myhandler 58 | - meta: flush_handlers 59 | 60 | # reload inventory, useful with dynamic inventories when play makes changes to the existing hosts 61 | - cloud_guest: # this is fake module 62 | name: newhost 63 | state: present 64 | 65 | - name: Refresh inventory to ensure new instaces exist in inventory 66 | meta: refresh_inventory 67 | 68 | - name: Clear gathered facts from all currently targeted hosts 69 | meta: clear_facts 70 | 71 | # bring host back to play after failure 72 | - copy: 73 | src: file 74 | dest: /etc/file 75 | remote_user: imightnothavepermission 76 | 77 | - meta: clear_host_errors 78 | ''' 79 | -------------------------------------------------------------------------------- /utilities/logic/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/utilities/logic/__init__.py -------------------------------------------------------------------------------- /utilities/logic/assert.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # Copyright 2012 Dag Wieers 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': 'core', 23 | 'version': '1.0'} 24 | 25 | DOCUMENTATION = ''' 26 | --- 27 | module: assert 28 | short_description: Asserts given expressions are true 29 | description: 30 | - This module asserts that given expressions are true with an optional custom message. 31 | version_added: "1.5" 32 | options: 33 | that: 34 | description: 35 | - "A string expression of the same form that can be passed to the 'when' statement" 36 | - "Alternatively, a list of string expressions" 37 | required: true 38 | msg: 39 | description: 40 | - "The customized message used for a failing assertion" 41 | required: false 42 | author: 43 | - "Ansible Core Team" 44 | - "Michael DeHaan" 45 | ''' 46 | 47 | EXAMPLES = ''' 48 | - assert: { that: "ansible_os_family != 'RedHat'" } 49 | 50 | - assert: 51 | that: 52 | - "'foo' in some_command_result.stdout" 53 | - "number_of_the_counting == 3" 54 | 55 | - assert: 56 | that: 57 | - "my_param <= 100" 58 | - "my_param >= 0" 59 | msg: "'my_param' must be between 0 and 100" 60 | ''' 61 | -------------------------------------------------------------------------------- /utilities/logic/async_status.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # (c) 2012, Michael DeHaan , and others 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': ['stableinterface'], 23 | 'supported_by': 'core', 24 | 'version': '1.0'} 25 | 26 | DOCUMENTATION = ''' 27 | --- 28 | module: async_status 29 | short_description: Obtain status of asynchronous task 30 | description: 31 | - "This module gets the status of an asynchronous task." 32 | version_added: "0.5" 33 | options: 34 | jid: 35 | description: 36 | - Job or task identifier 37 | required: true 38 | default: null 39 | aliases: [] 40 | mode: 41 | description: 42 | - if C(status), obtain the status; if C(cleanup), clean up the async job cache 43 | located in C(~/.ansible_async/) for the specified job I(jid). 44 | required: false 45 | choices: [ "status", "cleanup" ] 46 | default: "status" 47 | notes: 48 | - See also U(http://docs.ansible.com/playbooks_async.html) 49 | requirements: [] 50 | author: 51 | - "Ansible Core Team" 52 | - "Michael DeHaan" 53 | ''' 54 | 55 | import datetime 56 | import traceback 57 | from ansible.module_utils.six import iteritems 58 | 59 | def main(): 60 | 61 | module = AnsibleModule(argument_spec=dict( 62 | jid=dict(required=True), 63 | mode=dict(default='status', choices=['status','cleanup']), 64 | )) 65 | 66 | mode = module.params['mode'] 67 | jid = module.params['jid'] 68 | 69 | # setup logging directory 70 | logdir = os.path.expanduser("~/.ansible_async") 71 | log_path = os.path.join(logdir, jid) 72 | 73 | if not os.path.exists(log_path): 74 | module.fail_json(msg="could not find job", ansible_job_id=jid, started=1, finished=1) 75 | 76 | if mode == 'cleanup': 77 | os.unlink(log_path) 78 | module.exit_json(ansible_job_id=jid, erased=log_path) 79 | 80 | # NOT in cleanup mode, assume regular status mode 81 | # no remote kill mode currently exists, but probably should 82 | # consider log_path + ".pid" file and also unlink that above 83 | 84 | data = None 85 | try: 86 | data = open(log_path).read() 87 | data = json.loads(data) 88 | except Exception: 89 | if not data: 90 | # file not written yet? That means it is running 91 | module.exit_json(results_file=log_path, ansible_job_id=jid, started=1, finished=0) 92 | else: 93 | module.fail_json(ansible_job_id=jid, results_file=log_path, 94 | msg="Could not parse job output: %s" % data, started=1, finished=1) 95 | 96 | if not 'started' in data: 97 | data['finished'] = 1 98 | data['ansible_job_id'] = jid 99 | elif 'finished' not in data: 100 | data['finished'] = 0 101 | 102 | # Fix error: TypeError: exit_json() keywords must be strings 103 | data = dict([(str(k), v) for k, v in iteritems(data)]) 104 | 105 | module.exit_json(**data) 106 | 107 | # import module snippets 108 | from ansible.module_utils.basic import * 109 | 110 | if __name__ == '__main__': 111 | main() 112 | -------------------------------------------------------------------------------- /utilities/logic/debug.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # Copyright 2012 Dag Wieers 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': 'core', 23 | 'version': '1.0'} 24 | 25 | DOCUMENTATION = ''' 26 | --- 27 | module: debug 28 | short_description: Print statements during execution 29 | description: 30 | - This module prints statements during execution and can be useful 31 | for debugging variables or expressions without necessarily halting 32 | the playbook. Useful for debugging together with the 'when:' directive. 33 | 34 | version_added: "0.8" 35 | options: 36 | msg: 37 | description: 38 | - The customized message that is printed. If omitted, prints a generic 39 | message. 40 | required: false 41 | default: "Hello world!" 42 | var: 43 | description: 44 | - A variable name to debug. Mutually exclusive with the 'msg' option. 45 | verbosity: 46 | description: 47 | - A number that controls when the debug is run, if you set to 3 it will only run debug when -vvv or above 48 | required: False 49 | default: 0 50 | version_added: "2.1" 51 | author: 52 | - "Dag Wieers (@dagwieers)" 53 | - "Michael DeHaan" 54 | ''' 55 | 56 | EXAMPLES = ''' 57 | # Example that prints the loopback address and gateway for each host 58 | - debug: 59 | msg: "System {{ inventory_hostname }} has uuid {{ ansible_product_uuid }}" 60 | 61 | - debug: 62 | msg: "System {{ inventory_hostname }} has gateway {{ ansible_default_ipv4.gateway }}" 63 | when: ansible_default_ipv4.gateway is defined 64 | 65 | - shell: /usr/bin/uptime 66 | register: result 67 | 68 | - debug: 69 | var: result 70 | verbosity: 2 71 | 72 | - name: Display all variables/facts known for a host 73 | debug: 74 | var: hostvars[inventory_hostname] 75 | verbosity: 4 76 | ''' 77 | -------------------------------------------------------------------------------- /utilities/logic/fail.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # Copyright 2012 Dag Wieers 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': 'core', 23 | 'version': '1.0'} 24 | 25 | DOCUMENTATION = ''' 26 | --- 27 | module: fail 28 | short_description: Fail with custom message 29 | description: 30 | - This module fails the progress with a custom message. It can be 31 | useful for bailing out when a certain condition is met using C(when). 32 | version_added: "0.8" 33 | options: 34 | msg: 35 | description: 36 | - The customized message used for failing execution. If omitted, 37 | fail will simple bail out with a generic message. 38 | required: false 39 | default: "'Failed as requested from task'" 40 | 41 | author: "Dag Wieers (@dagwieers)" 42 | ''' 43 | 44 | EXAMPLES = ''' 45 | # Example playbook using fail and when together 46 | - fail: 47 | msg: "The system may not be provisioned according to the CMDB status." 48 | when: cmdb_status != "to-be-staged" 49 | ''' 50 | -------------------------------------------------------------------------------- /utilities/logic/include.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- mode: python -*- 3 | # Ansible is distributed in the hope that it will be useful, 4 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 5 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6 | # GNU General Public License for more details. 7 | # 8 | # You should have received a copy of the GNU General Public License 9 | # along with Ansible. If not, see . 10 | 11 | ANSIBLE_METADATA = {'status': ['preview'], 12 | 'supported_by': 'core', 13 | 'version': '1.0'} 14 | 15 | DOCUMENTATION = ''' 16 | --- 17 | author: 18 | - "Ansible Core Team (@ansible)" 19 | module: include 20 | short_description: include a play or task list. 21 | description: 22 | - Includes a file with a list of plays or tasks to be executed in the current playbook. 23 | - Files with a list of plays can only be included at the top level, lists of tasks can only be included where tasks normally run (in play). 24 | - Before 2.0 all includes were 'static', executed at play compile time. 25 | - Static includes are not subject to most directives, for example, loops or conditionals, they are applied instead to each inherited task. 26 | - Since 2.0 task includes are dynamic and behave more like real tasks. This means they can be looped, skipped and use variables from any source. 27 | Ansible tries to auto detect this, use the `static` directive (new in 2.1) to bypass autodetection. 28 | version_added: "0.6" 29 | options: 30 | free-form: 31 | description: 32 | - This module allows you to specify the name of the file directly w/o any other options. 33 | notes: 34 | - This is really not a module, though it appears as such, this is a feature of the Ansible Engine, as such it cannot be overridden the same way a module can. 35 | ''' 36 | 37 | EXAMPLES = """ 38 | # include a play after another play 39 | - hosts: localhost 40 | tasks: 41 | - debug: 42 | msg: "play1" 43 | 44 | - include: otherplays.yml 45 | 46 | 47 | # include task list in play 48 | - hosts: all 49 | tasks: 50 | - debug: 51 | msg: task1 52 | 53 | - include: stuff.yml 54 | 55 | - debug: 56 | msg: task10 57 | 58 | # dyanmic include task list in play 59 | - hosts: all 60 | tasks: 61 | - debug: 62 | msg: task1 63 | 64 | - include: "{{ hostvar }}.yml" 65 | static: no 66 | when: hostvar is defined 67 | """ 68 | 69 | RETURN = """ 70 | # this module does not return anything except plays or tasks to execute 71 | """ 72 | -------------------------------------------------------------------------------- /utilities/logic/include_role.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- mode: python -*- 3 | # Ansible is distributed in the hope that it will be useful, 4 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 5 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6 | # GNU General Public License for more details. 7 | # 8 | # You should have received a copy of the GNU General Public License 9 | # along with Ansible. If not, see . 10 | 11 | ANSIBLE_METADATA = {'status': ['preview'], 12 | 'supported_by': 'core', 13 | 'version': '1.0'} 14 | 15 | DOCUMENTATION = ''' 16 | --- 17 | author: 18 | - "Ansible Core Team (@ansible)" 19 | module: include_role 20 | short_description: Load and execute a role 21 | description: 22 | - "Loads and executes a role as a task, this frees roles from the `role:` directive and allows them to be treated more as tasks." 23 | version_added: "2.2" 24 | options: 25 | name: 26 | description: 27 | - The name of the role to be executed. 28 | required: True 29 | tasks_from: 30 | description: 31 | - "File to load from a Role's tasks/ directory." 32 | required: False 33 | default: 'main' 34 | vars_from: 35 | description: 36 | - "File to load from a Role's vars/ directory." 37 | required: False 38 | default: 'main' 39 | defaults_from: 40 | description: 41 | - "File to load from a Role's defaults/ directory." 42 | required: False 43 | default: 'main' 44 | static: 45 | description: 46 | - Gives Ansible a hint if this is a 'static' include or not. If static it implies that it won't need templating nor loops nor conditionals and will show included tasks in the --list options. 47 | required: False 48 | default: None 49 | allow_duplicates: 50 | description: 51 | - Overrides the role's metadata setting to allow using a role more than once with the same parameters. 52 | required: False 53 | default: True 54 | private: 55 | description: 56 | - If True the variables from defaults/ and vars/ in a role will not be made available to the rest of the play. 57 | default: None 58 | notes: 59 | - THIS IS EARLY PREVIEW, THINGS MAY CHANGE 60 | - Handlers are made available to the whole play. 61 | - simple dependencies seem to work fine. 62 | - "Things not tested (yet): plugin overrides, nesting includes, used as handler, other stuff I did not think of when I wrote this." 63 | ''' 64 | 65 | EXAMPLES = """ 66 | - include_role: 67 | name: myrole 68 | 69 | - name: Run tasks/other.yml instead of 'main' 70 | include_role: 71 | name: myrole 72 | tasks_from: other 73 | 74 | - name: Pass variables to role 75 | include_role: 76 | name: myrole 77 | vars: 78 | rolevar1: 'value from task' 79 | 80 | - name: Use role in loop 81 | include_role: 82 | name: myrole 83 | with_items: 84 | - "{{roleinput1}}" 85 | - "{{roleinput2}}" 86 | loop_control: 87 | loop_var: roleinputvar 88 | 89 | - name: conditional role 90 | include_role: 91 | name: myrole 92 | when: not idontwanttorun 93 | """ 94 | 95 | RETURN = """ 96 | # this module does not return anything except tasks to execute 97 | """ 98 | -------------------------------------------------------------------------------- /utilities/logic/include_vars.py: -------------------------------------------------------------------------------- 1 | # -*- mode: python -*- 2 | 3 | # Ansible is distributed in the hope that it will be useful, 4 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 5 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6 | # GNU General Public License for more details. 7 | # 8 | # You should have received a copy of the GNU General Public License 9 | # along with Ansible. If not, see . 10 | 11 | ANSIBLE_METADATA = {'status': ['stableinterface'], 12 | 'supported_by': 'core', 13 | 'version': '1.0'} 14 | 15 | DOCUMENTATION = ''' 16 | --- 17 | author: "Allen Sanabria (@linuxdynasty)" 18 | module: include_vars 19 | short_description: Load variables from files, dynamically within a task. 20 | description: 21 | - Loads variables from a YAML/JSON files dynamically from within a file or 22 | from a directory recursively during task runtime. If loading a directory, the files are sorted alphabetically before being loaded. 23 | version_added: "1.4" 24 | options: 25 | file: 26 | version_added: "2.2" 27 | description: 28 | - The file name from which variables should be loaded. 29 | - If the path is relative, it will look for the file in vars/ subdirectory of a role or relative to playbook. 30 | dir: 31 | version_added: "2.2" 32 | description: 33 | - The directory name from which the variables should be loaded. 34 | - If the path is relative, it will look for the file in vars/ subdirectory of a role or relative to playbook. 35 | default: null 36 | name: 37 | version_added: "2.2" 38 | description: 39 | - The name of a variable into which assign the included vars, if omitted (null) they will be made top level vars. 40 | default: null 41 | depth: 42 | version_added: "2.2" 43 | description: 44 | - By default, this module will recursively go through each sub directory and load up the variables. By explicitly setting the depth, this module will only go as deep as the depth. 45 | default: 0 46 | files_matching: 47 | version_added: "2.2" 48 | description: 49 | - Limit the variables that are loaded within any directory to this regular expression. 50 | default: null 51 | ignore_files: 52 | version_added: "2.2" 53 | description: 54 | - List of file names to ignore. The defaults can not be overridden, but can be extended. 55 | default: null 56 | free-form: 57 | description: 58 | - This module allows you to specify the 'file' option directly w/o any other options. 59 | ''' 60 | 61 | EXAMPLES = """ 62 | # Include vars of stuff.yml into the 'stuff' variable (2.2). 63 | - include_vars: 64 | file: stuff.yml 65 | name: stuff 66 | 67 | # Conditionally decide to load in variables into 'plans' when x is 0, otherwise do not. (2.2) 68 | - include_vars: 69 | file: contingency_plan.yml 70 | name: plans 71 | when: x == 0 72 | 73 | # Load a variable file based on the OS type, or a default if not found. 74 | - include_vars: "{{ item }}" 75 | with_first_found: 76 | - "{{ ansible_distribution }}.yml" 77 | - "{{ ansible_os_family }}.yml" 78 | - "default.yml" 79 | 80 | # bare include (free-form) 81 | - include_vars: myvars.yml 82 | 83 | # Include all yml files in vars/all and all nested directories 84 | - include_vars: 85 | dir: 'vars/all' 86 | 87 | # Include all yml files in vars/all and all nested directories and save the output in test. 88 | - include_vars: 89 | dir: 'vars/all' 90 | name: test 91 | 92 | # Include all yml files in vars/services 93 | - include_vars: 94 | dir: 'vars/services' 95 | depth: 1 96 | 97 | # Include only bastion.yml files 98 | - include_vars: 99 | dir: 'vars' 100 | files_matching: 'bastion.yml' 101 | 102 | # Include only all yml files exception bastion.yml 103 | - include_vars: 104 | dir: 'vars' 105 | ignore_files: 'bastion.yml' 106 | """ 107 | -------------------------------------------------------------------------------- /utilities/logic/pause.py: -------------------------------------------------------------------------------- 1 | # -*- mode: python -*- 2 | 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 | ANSIBLE_METADATA = {'status': ['stableinterface'], 19 | 'supported_by': 'core', 20 | 'version': '1.0'} 21 | 22 | DOCUMENTATION = ''' 23 | --- 24 | module: pause 25 | short_description: Pause playbook execution 26 | description: 27 | - Pauses playbook execution for a set amount of time, or until a prompt is acknowledged. All parameters are optional. The default behavior is to pause with a prompt. 28 | - "You can use C(ctrl+c) if you wish to advance a pause earlier than it is set to expire or if you need to abort a playbook run entirely. To continue early: press C(ctrl+c) and then C(c). To abort a playbook: press C(ctrl+c) and then C(a)." 29 | - "The pause module integrates into async/parallelized playbooks without any special considerations (see also: Rolling Updates). When using pauses with the C(serial) playbook parameter (as in rolling updates) you are only prompted once for the current group of hosts." 30 | version_added: "0.8" 31 | options: 32 | minutes: 33 | description: 34 | - A positive number of minutes to pause for. 35 | required: false 36 | default: null 37 | seconds: 38 | description: 39 | - A positive number of seconds to pause for. 40 | required: false 41 | default: null 42 | prompt: 43 | description: 44 | - Optional text to use for the prompt message. 45 | required: false 46 | default: null 47 | author: "Tim Bielawa (@tbielawa)" 48 | notes: 49 | - Starting in 2.2, if you specify 0 or negative for minutes or seconds, it will wait for 1 second, previously it would wait indefinitely. 50 | ''' 51 | 52 | EXAMPLES = ''' 53 | # Pause for 5 minutes to build app cache. 54 | - pause: 55 | minutes: 5 56 | 57 | # Pause until you can verify updates to an application were successful. 58 | - pause: 59 | 60 | # A helpful reminder of what to look out for post-update. 61 | - pause: 62 | prompt: "Make sure org.foo.FooOverload exception is not present" 63 | ''' 64 | -------------------------------------------------------------------------------- /utilities/logic/set_fact.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # Copyright 2013 Dag Wieers 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': 'core', 23 | 'version': '1.0'} 24 | 25 | DOCUMENTATION = ''' 26 | --- 27 | author: "Dag Wieers (@dagwieers)" 28 | module: set_fact 29 | short_description: Set host facts from a task 30 | description: 31 | - This module allows setting new variables. Variables are set on a host-by-host basis just like facts discovered by the setup module. 32 | - These variables will be available to subsequent plays during an ansible-playbook run, but will not be saved across executions even if you use a fact cache. 33 | options: 34 | key_value: 35 | description: 36 | - The C(set_fact) module takes key=value pairs as variables to set 37 | in the playbook scope. Or alternatively, accepts complex arguments 38 | using the C(args:) statement. 39 | required: true 40 | default: null 41 | version_added: "1.2" 42 | notes: 43 | - "The `var=value` notation can only create strings or booleans. 44 | If you want to create lists/arrays or dictionary/hashes use `var: [val1, val2]`" 45 | ''' 46 | 47 | EXAMPLES = ''' 48 | # Example setting host facts using key=value pairs, note that this always creates strings or booleans 49 | - set_fact: 50 | one_fact: "something" 51 | other_fact: "{{ local_var }}" 52 | 53 | # Example setting host facts using complex arguments 54 | - set_fact: 55 | one_fact: something 56 | other_fact: "{{ local_var * 2 }}" 57 | another_fact: "{{ some_registered_var.results | map(attribute='ansible_facts.some_fact') | list }}" 58 | 59 | # As of 1.8, Ansible will convert boolean strings ('true', 'false', 'yes', 'no') 60 | # to proper boolean values when using the key=value syntax, however it is still 61 | # recommended that booleans be set using the complex argument style: 62 | - set_fact: 63 | one_fact: true 64 | other_fact: false 65 | 66 | ''' 67 | -------------------------------------------------------------------------------- /web_infrastructure/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/web_infrastructure/__init__.py -------------------------------------------------------------------------------- /windows/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-modules-core/00911a75ad6635834b6d28eef41f197b2f73c381/windows/__init__.py -------------------------------------------------------------------------------- /windows/async_status.ps1: -------------------------------------------------------------------------------- 1 | #!powershell 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 | # WANT_JSON 18 | # POWERSHELL_COMMON 19 | 20 | $results = @{changed=$false} 21 | 22 | $parsed_args = Parse-Args $args 23 | $jid = Get-AnsibleParam $parsed_args "jid" -failifempty $true -resultobj $results 24 | $mode = Get-AnsibleParam $parsed_args "mode" -Default "status" -ValidateSet "status","cleanup" 25 | 26 | # setup logging directory 27 | $log_path = [System.IO.Path]::Combine($env:LOCALAPPDATA, ".ansible_async", $jid) 28 | 29 | If(-not $(Test-Path $log_path)) 30 | { 31 | Fail-Json @{ansible_job_id=$jid; started=1; finished=1} "could not find job" 32 | } 33 | 34 | If($mode -eq "cleanup") { 35 | Remove-Item $log_path -Recurse 36 | Exit-Json @{ansible_job_id=$jid; erased=$log_path} 37 | } 38 | 39 | # NOT in cleanup mode, assume regular status mode 40 | # no remote kill mode currently exists, but probably should 41 | # consider log_path + ".pid" file and also unlink that above 42 | 43 | $data = $null 44 | Try { 45 | $data_raw = Get-Content $log_path 46 | 47 | # TODO: move this into module_utils/powershell.ps1? 48 | $jss = New-Object System.Web.Script.Serialization.JavaScriptSerializer 49 | $data = $jss.DeserializeObject($data_raw) 50 | } 51 | Catch { 52 | If(-not $data_raw) { 53 | # file not written yet? That means it is running 54 | Exit-Json @{results_file=$log_path; ansible_job_id=$jid; started=1; finished=0} 55 | } 56 | Else { 57 | Fail-Json @{ansible_job_id=$jid; results_file=$log_path; started=1; finished=1} "Could not parse job output: $data" 58 | } 59 | } 60 | 61 | If (-not $data.ContainsKey("started")) { 62 | $data['finished'] = 1 63 | $data['ansible_job_id'] = $jid 64 | } 65 | ElseIf (-not $data.ContainsKey("finished")) { 66 | $data['finished'] = 0 67 | } 68 | 69 | Exit-Json $data 70 | -------------------------------------------------------------------------------- /windows/slurp.ps1: -------------------------------------------------------------------------------- 1 | #!powershell 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 | # WANT_JSON 18 | # POWERSHELL_COMMON 19 | 20 | $params = Parse-Args $args $true; 21 | 22 | $src = Get-Attr $params "src" (Get-Attr $params "path" $FALSE); 23 | If (-not $src) 24 | { 25 | Fail-Json (New-Object psobject) "missing required argument: src"; 26 | } 27 | 28 | If (Test-Path -PathType Leaf $src) 29 | { 30 | $bytes = [System.IO.File]::ReadAllBytes($src); 31 | $content = [System.Convert]::ToBase64String($bytes); 32 | $result = New-Object psobject @{ 33 | changed = $false 34 | encoding = "base64" 35 | content = $content 36 | }; 37 | Exit-Json $result; 38 | } 39 | ElseIf (Test-Path -PathType Container $src) 40 | { 41 | Fail-Json (New-Object psobject) ("is a directory: " + $src); 42 | } 43 | Else 44 | { 45 | Fail-Json (New-Object psobject) ("file not found: " + $src); 46 | } 47 | -------------------------------------------------------------------------------- /windows/win_command.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # (c) 2016, Ansible, 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 | ANSIBLE_METADATA = {'status': ['preview'], 23 | 'supported_by': 'core', 24 | 'version': '1.0'} 25 | 26 | DOCUMENTATION = ''' 27 | --- 28 | module: win_command 29 | short_description: Executes a command on a remote Windows node 30 | version_added: 2.2 31 | description: 32 | - The M(win_command) module takes the command name followed by a list of space-delimited arguments. 33 | - The given command will be executed on all selected nodes. It will not be 34 | processed through the shell, so variables like C($env:HOME) and operations 35 | like C("<"), C(">"), C("|"), and C(";") will not work (use the M(win_shell) 36 | module if you need these features). 37 | options: 38 | free_form: 39 | description: 40 | - the win_command module takes a free form command to run. There is no parameter actually named 'free form'. 41 | See the examples! 42 | required: true 43 | creates: 44 | description: 45 | - a path or path filter pattern; when the referenced path exists on the target host, the task will be skipped. 46 | removes: 47 | description: 48 | - a path or path filter pattern; when the referenced path B(does not) exist on the target host, the task will be skipped. 49 | chdir: 50 | description: 51 | - set the specified path as the current working directory before executing a command 52 | notes: 53 | - If you want to run a command through a shell (say you are using C(<), 54 | C(>), C(|), etc), you actually want the M(win_shell) module instead. The 55 | M(win_command) module is much more secure as it's not affected by the user's 56 | environment. 57 | - " C(creates), C(removes), and C(chdir) can be specified after the command. For instance, if you only want to run a command if a certain file does not exist, use this." 58 | author: 59 | - Matt Davis 60 | ''' 61 | 62 | EXAMPLES = ''' 63 | # Example from Ansible Playbooks. 64 | - win_command: whoami 65 | register: whoami_out 66 | 67 | # Run the command only if the specified file does not exist. 68 | - win_command: wbadmin -backupTarget:c:\\backup\\ creates=c:\\backup\\ 69 | 70 | # You can also use the 'args' form to provide the options. This command 71 | # will change the working directory to c:\\somedir\\ and will only run when 72 | # c:\\backup\\ doesn't exist. 73 | - win_command: wbadmin -backupTarget:c:\\backup\\ creates=c:\\backup\\ 74 | args: 75 | chdir: c:\\somedir\\ 76 | creates: c:\\backup\\ 77 | ''' 78 | 79 | RETURN = ''' 80 | msg: 81 | description: changed 82 | returned: always 83 | type: boolean 84 | sample: True 85 | start: 86 | description: The command execution start time 87 | returned: always 88 | type: string 89 | sample: '2016-02-25 09:18:26.429568' 90 | end: 91 | description: The command execution end time 92 | returned: always 93 | type: string 94 | sample: '2016-02-25 09:18:26.755339' 95 | delta: 96 | description: The command execution delta time 97 | returned: always 98 | type: string 99 | sample: '0:00:00.325771' 100 | stdout: 101 | description: The command standard output 102 | returned: always 103 | type: string 104 | sample: 'Clustering node rabbit@slave1 with rabbit@master ...' 105 | stderr: 106 | description: The command standard error 107 | returned: always 108 | type: string 109 | sample: 'ls: cannot access foo: No such file or directory' 110 | cmd: 111 | description: The command executed by the task 112 | returned: always 113 | type: string 114 | sample: 'rabbitmqctl join_cluster rabbit@master' 115 | rc: 116 | description: The command return code (0 means success) 117 | returned: always 118 | type: int 119 | sample: 0 120 | stdout_lines: 121 | description: The command standard output split in lines 122 | returned: always 123 | type: list of strings 124 | sample: [u'Clustering node rabbit@slave1 with rabbit@master ...'] 125 | ''' 126 | -------------------------------------------------------------------------------- /windows/win_copy.ps1: -------------------------------------------------------------------------------- 1 | #!powershell 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 | # WANT_JSON 18 | # POWERSHELL_COMMON 19 | 20 | $params = Parse-Args $args 21 | 22 | $src= Get-Attr $params "src" $FALSE 23 | If ($src -eq $FALSE) 24 | { 25 | Fail-Json (New-Object psobject) "missing required argument: src" 26 | } 27 | 28 | $dest= Get-Attr $params "dest" $FALSE 29 | If ($dest -eq $FALSE) 30 | { 31 | Fail-Json (New-Object psobject) "missing required argument: dest" 32 | } 33 | 34 | $original_basename = Get-Attr $params "original_basename" $FALSE 35 | If ($original_basename -eq $FALSE) 36 | { 37 | Fail-Json (New-Object psobject) "missing required argument: original_basename " 38 | } 39 | 40 | $result = New-Object psobject @{ 41 | changed = $FALSE 42 | original_basename = $original_basename 43 | } 44 | 45 | # original_basename gets set if src and dest are dirs 46 | # but includes subdir if the source folder contains sub folders 47 | # e.g. you could get subdir/foo.txt 48 | 49 | # detect if doing recursive folder copy and create any non-existent destination sub folder 50 | $parent = Split-Path -Path $original_basename -Parent 51 | if ($parent.length -gt 0) 52 | { 53 | $dest_folder = Join-Path $dest $parent 54 | New-Item -Force $dest_folder -Type directory 55 | } 56 | 57 | # if $dest is a dir, append $original_basename so the file gets copied with its intended name. 58 | if (Test-Path $dest -PathType Container) 59 | { 60 | $dest = Join-Path $dest $original_basename 61 | } 62 | 63 | $dest_checksum = Get-FileChecksum ($dest) 64 | $src_checksum = Get-FileChecksum ($src) 65 | 66 | If ($src_checksum.Equals($dest_checksum)) 67 | { 68 | # if both are "3" then both are folders, ok to copy 69 | If ($src_checksum.Equals("3")) 70 | { 71 | # New-Item -Force creates subdirs for recursive copies 72 | New-Item -Force $dest -Type file 73 | Copy-Item -Path $src -Destination $dest -Force 74 | $result.operation = "folder_copy" 75 | } 76 | 77 | } 78 | ElseIf (! $src_checksum.Equals($dest_checksum)) 79 | { 80 | If ($src_checksum.Equals("3")) 81 | { 82 | Fail-Json (New-Object psobject) "If src is a folder, dest must also be a folder" 83 | } 84 | # The checksums don't match, there's something to do 85 | Copy-Item -Path $src -Destination $dest -Force 86 | $result.operation = "file_copy" 87 | } 88 | 89 | # verify before we return that the file has changed 90 | $dest_checksum = Get-FileChecksum ($dest) 91 | If ( $src_checksum.Equals($dest_checksum)) 92 | { 93 | $result.changed = $TRUE 94 | } 95 | Else 96 | { 97 | Fail-Json (New-Object psobject) "src checksum $src_checksum did not match dest_checksum $dest_checksum Failed to place file $original_basename in $dest" 98 | } 99 | # generate return values 100 | 101 | $info = Get-Item $dest 102 | $result.size = $info.Length 103 | 104 | Exit-Json $result 105 | -------------------------------------------------------------------------------- /windows/win_copy.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 | 22 | ANSIBLE_METADATA = {'status': ['stableinterface'], 23 | 'supported_by': 'core', 24 | 'version': '1.0'} 25 | 26 | DOCUMENTATION = ''' 27 | --- 28 | module: win_copy 29 | version_added: "1.9.2" 30 | short_description: Copies files to remote locations on windows hosts. 31 | description: 32 | - The M(win_copy) module copies a file on the local box to remote windows locations. 33 | options: 34 | src: 35 | description: 36 | - Local path to a file to copy to the remote server; can be absolute or relative. 37 | If path is a directory, it is copied recursively. In this case, if path ends 38 | with "/", only inside contents of that directory are copied to destination. 39 | Otherwise, if it does not end with "/", the directory itself with all contents 40 | is copied. This behavior is similar to Rsync. 41 | required: false 42 | default: null 43 | aliases: [] 44 | dest: 45 | description: 46 | - Remote absolute path where the file should be copied to. If src is a directory, 47 | this must be a directory too. Use \\ for path separators. 48 | required: true 49 | default: null 50 | author: "Jon Hawkesworth (@jhawkesworth)" 51 | ''' 52 | 53 | EXAMPLES = ''' 54 | - name: Copy a single file 55 | win_copy: 56 | src: /srv/myfiles/foo.conf 57 | dest: c:\TEMP\foo.conf 58 | 59 | - name: Copy files/temp_files to c:\temp 60 | win_copy: 61 | src: files/temp_files/ 62 | dest: c:\temp 63 | ''' 64 | RETURN = ''' 65 | dest: 66 | description: destination file/path 67 | returned: changed 68 | type: string 69 | sample: 'c:\temp' 70 | src: 71 | description: source file used for the copy on the target machine 72 | returned: changed 73 | type: string 74 | sample: "/home/httpd/.ansible/tmp/ansible-tmp-1423796390.97-147729857856000/source" 75 | checksum: 76 | description: sha1 checksum of the file after running copy 77 | returned: success 78 | type: string 79 | sample: "6e642bb8dd5c2e027bf21dd923337cbb4214f827" 80 | size: 81 | description: size of the target, after execution 82 | returned: changed (single files only) 83 | type: int 84 | sample: 1220 85 | operation: 86 | description: whether a single file copy took place or a folder copy 87 | returned: changed (single files only) 88 | type: string 89 | sample: "file_copy" 90 | original_basename: 91 | description: basename of the copied file 92 | returned: changed (single files only) 93 | type: string 94 | sample: "foo.txt" 95 | ''' 96 | 97 | -------------------------------------------------------------------------------- /windows/win_feature.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # (c) 2014, Paul Durivage , Trond Hindenes and others 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_feature 31 | version_added: "1.7" 32 | short_description: Installs and uninstalls Windows Features on Windows Server 33 | description: 34 | - Installs or uninstalls Windows Roles or Features on Windows Server. This module uses the Add/Remove-WindowsFeature Cmdlets, which is not available on client os machines. 35 | options: 36 | name: 37 | description: 38 | - Names of roles or features to install as a single feature or a comma-separated list of features 39 | required: true 40 | default: null 41 | state: 42 | description: 43 | - State of the features or roles on the system 44 | required: false 45 | choices: 46 | - present 47 | - absent 48 | default: present 49 | restart: 50 | description: 51 | - Restarts the computer automatically when installation is complete, if restarting is required by the roles or features installed. 52 | choices: 53 | - yes 54 | - no 55 | default: null 56 | required: false 57 | include_sub_features: 58 | description: 59 | - Adds all subfeatures of the specified feature 60 | choices: 61 | - yes 62 | - no 63 | default: null 64 | required: false 65 | include_management_tools: 66 | description: 67 | - Adds the corresponding management tools to the specified feature 68 | choices: 69 | - yes 70 | - no 71 | default: null 72 | required: false 73 | source: 74 | description: 75 | - Specify a source to install the feature from 76 | required: false 77 | choices: [ ' {driveletter}:\sources\sxs', ' {IP}\Share\sources\sxs' ] 78 | version_added: "2.1" 79 | author: 80 | - "Paul Durivage (@angstwad)" 81 | - "Trond Hindenes (@trondhindenes)" 82 | ''' 83 | 84 | EXAMPLES = r''' 85 | # This installs IIS. 86 | # The names of features available for install can be run by running the following Powershell Command: 87 | # PS C:\Users\Administrator> Import-Module ServerManager; Get-WindowsFeature 88 | $ ansible -i hosts -m win_feature -a "name=Web-Server" all 89 | $ ansible -i hosts -m win_feature -a "name=Web-Server,Web-Common-Http" all 90 | ansible -m "win_feature" -a "name=NET-Framework-Core source=C:/Temp/iso/sources/sxs" windows 91 | 92 | 93 | # Playbook example 94 | --- 95 | - name: Install IIS 96 | hosts: all 97 | gather_facts: false 98 | tasks: 99 | - name: Install IIS 100 | win_feature: 101 | name: "Web-Server" 102 | state: present 103 | restart: yes 104 | include_sub_features: yes 105 | include_management_tools: yes 106 | ''' 107 | -------------------------------------------------------------------------------- /windows/win_file.ps1: -------------------------------------------------------------------------------- 1 | #!powershell 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 | # WANT_JSON 18 | # POWERSHELL_COMMON 19 | 20 | $ErrorActionPreference = "Stop" 21 | 22 | $params = Parse-Args $args 23 | 24 | # path 25 | $path = Get-Attr $params "path" $FALSE 26 | If ($path -eq $FALSE) 27 | { 28 | $path = Get-Attr $params "dest" $FALSE 29 | If ($path -eq $FALSE) 30 | { 31 | $path = Get-Attr $params "name" $FALSE 32 | If ($path -eq $FALSE) 33 | { 34 | Fail-Json (New-Object psobject) "missing required argument: path" 35 | } 36 | } 37 | } 38 | 39 | # JH Following advice from Chris Church, only allow the following states 40 | # in the windows version for now: 41 | # state - file, directory, touch, absent 42 | # (originally was: state - file, link, directory, hard, touch, absent) 43 | 44 | $state = Get-Attr $params "state" "unspecified" 45 | # if state is not supplied, test the $path to see if it looks like 46 | # a file or a folder and set state to file or folder 47 | 48 | # result 49 | $result = New-Object psobject @{ 50 | changed = $FALSE 51 | } 52 | 53 | If ( $state -eq "touch" ) 54 | { 55 | If(Test-Path $path) 56 | { 57 | (Get-ChildItem $path).LastWriteTime = Get-Date 58 | } 59 | Else 60 | { 61 | echo $null > $path 62 | } 63 | $result.changed = $TRUE 64 | } 65 | 66 | If (Test-Path $path) 67 | { 68 | $fileinfo = Get-Item $path 69 | If ( $state -eq "absent" ) 70 | { 71 | Remove-Item -Recurse -Force $fileinfo 72 | $result.changed = $TRUE 73 | } 74 | Else 75 | { 76 | If ( $state -eq "directory" -and -not $fileinfo.PsIsContainer ) 77 | { 78 | Fail-Json (New-Object psobject) "path is not a directory" 79 | } 80 | 81 | If ( $state -eq "file" -and $fileinfo.PsIsContainer ) 82 | { 83 | Fail-Json (New-Object psobject) "path is not a file" 84 | } 85 | } 86 | } 87 | Else 88 | # doesn't yet exist 89 | { 90 | If ( $state -eq "unspecified" ) 91 | { 92 | $basename = Split-Path -Path $path -Leaf 93 | If ($basename.length -gt 0) 94 | { 95 | $state = "file" 96 | } 97 | Else 98 | { 99 | $state = "directory" 100 | } 101 | } 102 | 103 | If ( $state -eq "directory" ) 104 | { 105 | New-Item -ItemType directory -Path $path | Out-Null 106 | $result.changed = $TRUE 107 | } 108 | 109 | If ( $state -eq "file" ) 110 | { 111 | Fail-Json (New-Object psobject) "path will not be created" 112 | } 113 | } 114 | 115 | Exit-Json $result 116 | -------------------------------------------------------------------------------- /windows/win_file.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 | 22 | ANSIBLE_METADATA = {'status': ['stableinterface'], 23 | 'supported_by': 'core', 24 | 'version': '1.0'} 25 | 26 | DOCUMENTATION = ''' 27 | --- 28 | module: win_file 29 | version_added: "1.9.2" 30 | short_description: Creates, touches or removes files or directories. 31 | description: 32 | - Creates (empty) files, updates file modification stamps of existing files, 33 | and can create or remove directories. 34 | Unlike M(file), does not modify ownership, permissions or manipulate links. 35 | notes: 36 | - See also M(win_copy), M(win_template), M(copy), M(template), M(assemble) 37 | requirements: [ ] 38 | author: "Jon Hawkesworth (@jhawkesworth)" 39 | options: 40 | path: 41 | description: 42 | - 'path to the file being managed. Aliases: I(dest), I(name)' 43 | required: true 44 | default: [] 45 | aliases: ['dest', 'name'] 46 | state: 47 | description: 48 | - If C(directory), all immediate subdirectories will be created if they 49 | do not exist. 50 | If C(file), the file will NOT be created if it does not exist, see the M(copy) 51 | or M(template) module if you want that behavior. If C(absent), 52 | directories will be recursively deleted, and files will be removed. 53 | If C(touch), an empty file will be created if the C(path) does not 54 | exist, while an existing file or directory will receive updated file access and 55 | modification times (similar to the way C(touch) works from the command line). 56 | required: false 57 | default: file 58 | choices: [ file, directory, touch, absent ] 59 | ''' 60 | 61 | EXAMPLES = ''' 62 | - name: Create a file 63 | win_file: 64 | path: C:\temp\foo.conf 65 | state: file 66 | 67 | - name: Touch a file (creates if not present, updates modification time if present) 68 | win_file: 69 | path: C:\temp\foo.conf 70 | state: touch 71 | 72 | - name: Remove a file, if present 73 | win_file: 74 | path: C:\temp\foo.conf 75 | state: absent 76 | 77 | - name: Create directory structure 78 | win_file: 79 | path: C:\temp\folder\subfolder 80 | state: directory 81 | 82 | - name: Remove directory structure 83 | win_file: 84 | path: C:\temp 85 | state: absent 86 | ''' 87 | -------------------------------------------------------------------------------- /windows/win_get_url.ps1: -------------------------------------------------------------------------------- 1 | #!powershell 2 | # This file is part of Ansible. 3 | # 4 | # (c)) 2015, Paul Durivage , Tal Auslander 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_get_url = New-Object psobject 26 | changed = $false 27 | } 28 | 29 | $url = Get-AnsibleParam $params -name "url" -failifempty $true 30 | $dest = Get-AnsibleParam $params -name "dest" -failifempty $true 31 | 32 | $skip_certificate_validation = Get-AnsibleParam $params -name "skip_certificate_validation" -default $false 33 | $skip_certificate_validation = $skip_certificate_validation | ConvertTo-Bool 34 | $username = Get-AnsibleParam $params "username" 35 | $password = Get-AnsibleParam $params "password" 36 | 37 | $proxy_url = Get-AnsibleParam $params "proxy_url" 38 | $proxy_username = Get-AnsibleParam $params "proxy_username" 39 | $proxy_password = Get-AnsibleParam $params "proxy_password" 40 | 41 | if($skip_certificate_validation){ 42 | [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} 43 | } 44 | 45 | $force = Get-AnsibleParam -obj $params -name "force" -default $true 46 | $force = $force | ConvertTo-Bool 47 | 48 | Function Download-File($result, $url, $dest, $username, $password, $proxy_url, $proxy_username, $proxy_password) { 49 | $webClient = New-Object System.Net.WebClient 50 | if($proxy_url) { 51 | $proxy_server = New-Object System.Net.WebProxy($proxy_url, $true) 52 | if($proxy_username -and $proxy_password){ 53 | $proxy_credential = New-Object System.Net.NetworkCredential($proxy_username, $proxy_password) 54 | $proxy_server.Credentials = $proxy_credential 55 | } 56 | $webClient.Proxy = $proxy_server 57 | } 58 | 59 | if($username -and $password){ 60 | $webClient.Credentials = New-Object System.Net.NetworkCredential($username, $password) 61 | } 62 | 63 | Try { 64 | $webClient.DownloadFile($url, $dest) 65 | $result.changed = $true 66 | } 67 | Catch { 68 | Fail-Json $result "Error downloading $url to $dest $($_.Exception.Message)" 69 | } 70 | 71 | } 72 | 73 | 74 | If ($force -or -not (Test-Path $dest)) { 75 | Download-File -result $result -url $url -dest $dest -username $username -password $password -proxy_url $proxy_url -proxy_username $proxy_username -proxy_password $proxy_password 76 | 77 | } 78 | Else { 79 | $fileLastMod = ([System.IO.FileInfo]$dest).LastWriteTimeUtc 80 | $webLastMod = $null 81 | 82 | Try { 83 | $webRequest = [System.Net.HttpWebRequest]::Create($url) 84 | 85 | if($username -and $password){ 86 | $webRequest.Credentials = New-Object System.Net.NetworkCredential($username, $password) 87 | } 88 | 89 | $webRequest.Method = "HEAD" 90 | [System.Net.HttpWebResponse]$webResponse = $webRequest.GetResponse() 91 | 92 | $webLastMod = $webResponse.GetResponseHeader("Last-Modified") 93 | $webResponse.Close() 94 | } 95 | Catch { 96 | Fail-Json $result "Error when requesting Last-Modified date from $url $($_.Exception.Message)" 97 | } 98 | 99 | If (($webLastMod) -and ((Get-Date -Date $webLastMod ) -lt $fileLastMod)) { 100 | $result.changed = $false 101 | } Else { 102 | Download-File -result $result -url $url -dest $dest -username $username -password $password -proxy_url $proxy_url -proxy_username $proxy_username -proxy_password $proxy_password 103 | } 104 | 105 | } 106 | 107 | Set-Attr $result.win_get_url "url" $url 108 | Set-Attr $result.win_get_url "dest" $dest 109 | 110 | Exit-Json $result; 111 | -------------------------------------------------------------------------------- /windows/win_get_url.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # (c) 2014, Paul Durivage , and others 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': ['stableinterface'], 25 | 'supported_by': 'core', 26 | 'version': '1.0'} 27 | 28 | DOCUMENTATION = ''' 29 | --- 30 | module: win_get_url 31 | version_added: "1.7" 32 | short_description: Fetches a file from a given URL 33 | description: 34 | - Fetches a file from a URL and saves to locally 35 | author: 36 | - "Paul Durivage (@angstwad)" 37 | - "Takeshi Kuramochi (tksarah)" 38 | options: 39 | url: 40 | description: 41 | - The full URL of a file to download 42 | required: true 43 | default: null 44 | dest: 45 | description: 46 | - The absolute path of the location to save the file at the URL. Be sure 47 | to include a filename and extension as appropriate. 48 | required: true 49 | default: null 50 | force: 51 | description: 52 | - If C(yes), will always download the file. If C(no), will only 53 | download the file if it does not exist or the remote file has been 54 | modified more recently than the local file. This works by sending 55 | an http HEAD request to retrieve last modified time of the requested 56 | resource, so for this to work, the remote web server must support 57 | HEAD requests. 58 | version_added: "2.0" 59 | required: false 60 | choices: [ "yes", "no" ] 61 | default: yes 62 | username: 63 | description: 64 | - Basic authentication username 65 | required: false 66 | default: null 67 | password: 68 | description: 69 | - Basic authentication password 70 | required: false 71 | default: null 72 | skip_certificate_validation: 73 | description: 74 | - Skip SSL certificate validation if true 75 | required: false 76 | default: false 77 | proxy_url: 78 | description: 79 | - The full URL of the proxy server to download through. 80 | version_added: "2.0" 81 | required: false 82 | proxy_username: 83 | description: 84 | - Proxy authentication username 85 | version_added: "2.0" 86 | required: false 87 | proxy_password: 88 | description: 89 | - Proxy authentication password 90 | version_added: "2.0" 91 | required: false 92 | ''' 93 | 94 | EXAMPLES = r''' 95 | # Downloading a JPEG and saving it to a file with the ansible command. 96 | # Note the "dest" is quoted rather instead of escaping the backslashes 97 | $ ansible -i hosts -c winrm -m win_get_url -a "url=http://www.example.com/earthrise.jpg dest='C:\\Users\\Administrator\\earthrise.jpg'" all 98 | 99 | # Playbook example 100 | - name: Download earthrise.jpg to 'C:\\Users\\RandomUser\\earthrise.jpg' 101 | win_get_url: 102 | url: http://www.example.com/earthrise.jpg 103 | dest: C:\Users\RandomUser\earthrise.jpg 104 | 105 | - name: Download earthrise.jpg to 'C:\Users\RandomUser\earthrise.jpg' only if modified 106 | win_get_url: 107 | url: http://www.example.com/earthrise.jpg 108 | dest: C:\Users\RandomUser\earthrise.jpg 109 | force: no 110 | 111 | - name: Download earthrise.jpg to 'C:\Users\RandomUser\earthrise.jpg' through a proxy server. 112 | win_get_url: 113 | url: http://www.example.com/earthrise.jpg 114 | dest: C:\Users\RandomUser\earthrise.jpg 115 | proxy_url: http://10.0.0.1:8080 116 | proxy_username: username 117 | proxy_password: password 118 | ''' 119 | RETURN = ''' 120 | url: 121 | description: requested url 122 | returned: always 123 | type: string 124 | sample: http://www.example.com/earthrise.jpg 125 | dest: 126 | description: destination file/path 127 | returned: always 128 | type: string 129 | sample: 'C:\\Users\\RandomUser\\earthrise.jpg' 130 | ''' 131 | -------------------------------------------------------------------------------- /windows/win_group.ps1: -------------------------------------------------------------------------------- 1 | #!powershell 2 | # This file is part of Ansible 3 | # 4 | # Copyright 2014, Chris Hoffman 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 | Set-Attr $result "changed" $false; 26 | 27 | $name = Get-Attr $params "name" -failifempty $true 28 | 29 | $state = Get-Attr $params "state" "present" 30 | $state = $state.ToString().ToLower() 31 | If (($state -ne "present") -and ($state -ne "absent")) { 32 | Fail-Json $result "state is '$state'; must be 'present' or 'absent'" 33 | } 34 | 35 | $description = Get-Attr $params "description" $null 36 | 37 | $adsi = [ADSI]"WinNT://$env:COMPUTERNAME" 38 | $group = $adsi.Children | Where-Object {$_.SchemaClassName -eq 'group' -and $_.Name -eq $name } 39 | 40 | try { 41 | If ($state -eq "present") { 42 | If (-not $group) { 43 | $group = $adsi.Create("Group", $name) 44 | $group.SetInfo() 45 | 46 | Set-Attr $result "changed" $true 47 | } 48 | 49 | If ($null -ne $description) { 50 | IF (-not $group.description -or $group.description -ne $description) { 51 | $group.description = $description 52 | $group.SetInfo() 53 | Set-Attr $result "changed" $true 54 | } 55 | } 56 | } 57 | ElseIf ($state -eq "absent" -and $group) { 58 | $adsi.delete("Group", $group.Name.Value) 59 | Set-Attr $result "changed" $true 60 | } 61 | } 62 | catch { 63 | Fail-Json $result $_.Exception.Message 64 | } 65 | 66 | Exit-Json $result 67 | -------------------------------------------------------------------------------- /windows/win_group.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # (c) 2014, Chris Hoffman 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': ['stableinterface'], 25 | 'supported_by': 'core', 26 | 'version': '1.0'} 27 | 28 | DOCUMENTATION = ''' 29 | --- 30 | module: win_group 31 | version_added: "1.7" 32 | short_description: Add and remove local groups 33 | description: 34 | - Add and remove local groups 35 | options: 36 | name: 37 | description: 38 | - Name of the group 39 | required: true 40 | default: null 41 | aliases: [] 42 | description: 43 | description: 44 | - Description of the group 45 | required: false 46 | default: null 47 | aliases: [] 48 | state: 49 | description: 50 | - Create or remove the group 51 | required: false 52 | choices: 53 | - present 54 | - absent 55 | default: present 56 | aliases: [] 57 | author: "Chris Hoffman (@chrishoffman)" 58 | ''' 59 | 60 | EXAMPLES = ''' 61 | - name: Create a new group 62 | win_group: 63 | name: deploy 64 | description: Deploy Group 65 | state: present 66 | 67 | - name: Remove a group 68 | win_group: 69 | name: deploy 70 | state: absent 71 | ''' 72 | -------------------------------------------------------------------------------- /windows/win_msi.ps1: -------------------------------------------------------------------------------- 1 | #!powershell 2 | # (c) 2014, Matt Martz , and others 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 | # WANT_JSON 20 | # POWERSHELL_COMMON 21 | 22 | $params = Parse-Args $args; 23 | 24 | $path = Get-Attr $params "path" -failifempty $true 25 | $state = Get-Attr $params "state" "present" 26 | $creates = Get-Attr $params "creates" $false 27 | $extra_args = Get-Attr $params "extra_args" "" 28 | $wait = Get-Attr $params "wait" $false | ConvertTo-Bool 29 | 30 | $result = New-Object psobject @{ 31 | changed = $false 32 | }; 33 | 34 | If (($creates -ne $false) -and ($state -ne "absent") -and (Test-Path $creates)) 35 | { 36 | Exit-Json $result; 37 | } 38 | 39 | $logfile = [IO.Path]::GetTempFileName(); 40 | if ($state -eq "absent") 41 | { 42 | If ($wait) 43 | { 44 | Start-Process -FilePath msiexec.exe -ArgumentList "/x `"$path`" /qn /l $logfile $extra_args" -Verb Runas -Wait; 45 | } 46 | Else 47 | { 48 | Start-Process -FilePath msiexec.exe -ArgumentList "/x `"$path`" /qn /l $logfile $extra_args" -Verb Runas; 49 | } 50 | } 51 | Else 52 | { 53 | If ($wait) 54 | { 55 | Start-Process -FilePath msiexec.exe -ArgumentList "/i `"$path`" /qn /l $logfile $extra_args" -Verb Runas -Wait; 56 | } 57 | Else 58 | { 59 | Start-Process -FilePath msiexec.exe -ArgumentList "/i `"$path`" /qn /l $logfile $extra_args" -Verb Runas; 60 | } 61 | } 62 | 63 | Set-Attr $result "changed" $true; 64 | 65 | $logcontents = Get-Content $logfile | Out-String; 66 | Remove-Item $logfile; 67 | 68 | Set-Attr $result "log" $logcontents; 69 | 70 | Exit-Json $result; -------------------------------------------------------------------------------- /windows/win_msi.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # (c) 2014, Matt Martz , and others 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': ['deprecated'], 25 | 'supported_by': 'community', 26 | 'version': '1.0'} 27 | 28 | DOCUMENTATION = ''' 29 | --- 30 | module: win_msi 31 | version_added: "1.7" 32 | short_description: Installs and uninstalls Windows MSI files 33 | description: 34 | - Installs or uninstalls a Windows MSI file that is already located on the 35 | target server 36 | options: 37 | path: 38 | description: 39 | - File system path to the MSI file to install 40 | required: true 41 | extra_args: 42 | description: 43 | - Additional arguments to pass to the msiexec.exe command 44 | required: false 45 | state: 46 | description: 47 | - Whether the MSI file should be installed or uninstalled 48 | choices: 49 | - present 50 | - absent 51 | default: present 52 | creates: 53 | description: 54 | - Path to a file created by installing the MSI to prevent from 55 | attempting to reinstall the package on every run 56 | wait: 57 | version_added: "2.1" 58 | description: 59 | - Specify whether to wait for install or uninstall to complete before continuing. 60 | choices: 61 | - true 62 | - false 63 | default: false 64 | author: "Matt Martz (@sivel)" 65 | ''' 66 | 67 | EXAMPLES = ''' 68 | - name: Install an MSI file 69 | win_msi: 70 | path: C:\7z920-x64.msi 71 | 72 | - name: Install an MSI, and wait for it to complete before continuing 73 | win_msi: 74 | path: C:\7z920-x64.msi 75 | wait: true 76 | 77 | - name: Uninstall an MSI file 78 | win_msi: 79 | path: C:\7z920-x64.msi 80 | state: absent 81 | ''' 82 | 83 | -------------------------------------------------------------------------------- /windows/win_ping.ps1: -------------------------------------------------------------------------------- 1 | #!powershell 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 | # WANT_JSON 18 | # POWERSHELL_COMMON 19 | 20 | $params = Parse-Args $args $true; 21 | 22 | $data = Get-Attr $params "data" "pong"; 23 | 24 | $result = New-Object psobject @{ 25 | changed = $false 26 | ping = $data 27 | }; 28 | 29 | Exit-Json $result; 30 | -------------------------------------------------------------------------------- /windows/win_ping.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # (c) 2012, Michael DeHaan , and others 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': ['stableinterface'], 25 | 'supported_by': 'core', 26 | 'version': '1.0'} 27 | 28 | DOCUMENTATION = ''' 29 | --- 30 | module: win_ping 31 | version_added: "1.7" 32 | short_description: A windows version of the classic ping module. 33 | description: 34 | - Checks management connectivity of a windows host 35 | options: 36 | data: 37 | description: 38 | - Alternate data to return instead of 'pong' 39 | required: false 40 | default: 'pong' 41 | aliases: [] 42 | author: "Chris Church (@cchurch)" 43 | ''' 44 | 45 | EXAMPLES = ''' 46 | # Test connectivity to a windows host 47 | ansible winserver -m win_ping 48 | 49 | # Example from an Ansible Playbook 50 | - action: win_ping 51 | ''' 52 | 53 | -------------------------------------------------------------------------------- /windows/win_reboot.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 | # this is a windows documentation stub. actual code lives in the .ps1 20 | # file of the same name 21 | 22 | ANSIBLE_METADATA = {'status': ['stableinterface'], 23 | 'supported_by': 'core', 24 | 'version': '1.0'} 25 | 26 | DOCUMENTATION=''' 27 | --- 28 | module: win_reboot 29 | short_description: Reboot a windows machine 30 | description: 31 | - Reboot a Windows machine, wait for it to go down, come back up, and respond to commands. 32 | version_added: "2.1" 33 | options: 34 | pre_reboot_delay_sec: 35 | description: 36 | - Seconds for shutdown to wait before requesting reboot 37 | default: 2 38 | shutdown_timeout_sec: 39 | description: 40 | - Maximum seconds to wait for shutdown to occur 41 | - Increase this timeout for very slow hardware, large update applications, etc 42 | default: 600 43 | reboot_timeout_sec: 44 | description: 45 | - Maximum seconds to wait for machine to re-appear on the network and respond to a test command 46 | - This timeout is evaluated separately for both network appearance and test command success (so maximum clock time is actually twice this value) 47 | default: 600 48 | connect_timeout_sec: 49 | description: 50 | - Maximum seconds to wait for a single successful TCP connection to the WinRM endpoint before trying again 51 | default: 5 52 | test_command: 53 | description: 54 | - Command to expect success for to determine the machine is ready for management 55 | default: whoami 56 | author: 57 | - Matt Davis (@nitzmahone) 58 | ''' 59 | 60 | EXAMPLES=''' 61 | # unconditionally reboot the machine with all defaults 62 | - win_reboot: 63 | 64 | # apply updates and reboot if necessary 65 | - win_updates: 66 | register: update_result 67 | - win_reboot: 68 | when: update_result.reboot_required 69 | 70 | # reboot a slow machine that might have lots of updates to apply 71 | - win_reboot: 72 | shutdown_timeout_sec: 3600 73 | reboot_timeout_sec: 3600 74 | ''' 75 | 76 | RETURNS=''' 77 | rebooted: 78 | description: true if the machine was rebooted 79 | returned: always 80 | type: boolean 81 | sample: true 82 | ''' 83 | -------------------------------------------------------------------------------- /windows/win_service.ps1: -------------------------------------------------------------------------------- 1 | #!powershell 2 | # This file is part of Ansible 3 | # 4 | # Copyright 2014, Chris Hoffman 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 | Set-Attr $result "changed" $false; 26 | 27 | $name = Get-Attr $params "name" -failifempty $true 28 | $state = Get-Attr $params "state" $false 29 | $startMode = Get-Attr $params "start_mode" $false 30 | 31 | If ($state) { 32 | $state = $state.ToString().ToLower() 33 | If (($state -ne 'started') -and ($state -ne 'stopped') -and ($state -ne 'restarted')) { 34 | Fail-Json $result "state is '$state'; must be 'started', 'stopped', or 'restarted'" 35 | } 36 | } 37 | 38 | If ($startMode) { 39 | $startMode = $startMode.ToString().ToLower() 40 | If (($startMode -ne 'auto') -and ($startMode -ne 'manual') -and ($startMode -ne 'disabled')) { 41 | Fail-Json $result "start mode is '$startMode'; must be 'auto', 'manual', or 'disabled'" 42 | } 43 | } 44 | 45 | $svcName = $name 46 | $svc = Get-Service -Name $svcName -ErrorAction SilentlyContinue 47 | If (-not $svc) { 48 | Fail-Json $result "Service '$svcName' not installed" 49 | } 50 | # Use service name instead of display name for remaining actions. 51 | If ($svcName -ne $svc.ServiceName) { 52 | $svcName = $svc.ServiceName 53 | } 54 | 55 | Set-Attr $result "name" $svc.ServiceName 56 | Set-Attr $result "display_name" $svc.DisplayName 57 | 58 | $svcMode = Get-WmiObject -Class Win32_Service -Property StartMode -Filter "Name='$svcName'" 59 | If ($startMode) { 60 | If ($svcMode.StartMode.ToLower() -ne $startMode) { 61 | Set-Service -Name $svcName -StartupType $startMode 62 | Set-Attr $result "changed" $true 63 | Set-Attr $result "start_mode" $startMode 64 | } 65 | Else { 66 | Set-Attr $result "start_mode" $svcMode.StartMode.ToLower() 67 | } 68 | } 69 | Else { 70 | Set-Attr $result "start_mode" $svcMode.StartMode.ToLower() 71 | } 72 | 73 | If ($state) { 74 | If ($state -eq "started" -and $svc.Status -ne "Running") { 75 | try { 76 | Start-Service -Name $svcName -ErrorAction Stop 77 | } 78 | catch { 79 | Fail-Json $result $_.Exception.Message 80 | } 81 | Set-Attr $result "changed" $true; 82 | } 83 | ElseIf ($state -eq "stopped" -and $svc.Status -ne "Stopped") { 84 | try { 85 | Stop-Service -Name $svcName -ErrorAction Stop 86 | } 87 | catch { 88 | Fail-Json $result $_.Exception.Message 89 | } 90 | Set-Attr $result "changed" $true; 91 | } 92 | ElseIf ($state -eq "restarted") { 93 | try { 94 | Restart-Service -Name $svcName -ErrorAction Stop 95 | } 96 | catch { 97 | Fail-Json $result $_.Exception.Message 98 | } 99 | Set-Attr $result "changed" $true; 100 | } 101 | } 102 | $svc.Refresh() 103 | Set-Attr $result "state" $svc.Status.ToString().ToLower() 104 | 105 | Exit-Json $result; 106 | -------------------------------------------------------------------------------- /windows/win_service.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # (c) 2014, Chris Hoffman 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': ['stableinterface'], 25 | 'supported_by': 'core', 26 | 'version': '1.0'} 27 | 28 | DOCUMENTATION = ''' 29 | --- 30 | module: win_service 31 | version_added: "1.7" 32 | short_description: Manages Windows services 33 | description: 34 | - Manages Windows services 35 | options: 36 | name: 37 | description: 38 | - Name of the service 39 | required: true 40 | default: null 41 | aliases: [] 42 | start_mode: 43 | description: 44 | - Set the startup type for the service 45 | required: false 46 | choices: 47 | - auto 48 | - manual 49 | - disabled 50 | state: 51 | description: 52 | - C(started)/C(stopped) are idempotent actions that will not run 53 | commands unless necessary. C(restarted) will always bounce the 54 | service. 55 | required: false 56 | choices: 57 | - started 58 | - stopped 59 | - restarted 60 | default: null 61 | aliases: [] 62 | author: "Chris Hoffman (@chrishoffman)" 63 | ''' 64 | 65 | EXAMPLES = ''' 66 | - name: Restart a service 67 | win_service: 68 | name: spooler 69 | state: restarted 70 | 71 | - name: Set service startup mode to auto and ensure it is started 72 | win_service: 73 | name: spooler 74 | start_mode: auto 75 | state: started 76 | ''' 77 | -------------------------------------------------------------------------------- /windows/win_shell.ps1: -------------------------------------------------------------------------------- 1 | #!powershell 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 | # WANT_JSON 18 | # POWERSHELL_COMMON 19 | 20 | # TODO: add check mode support 21 | 22 | Set-StrictMode -Version 2 23 | $ErrorActionPreference = "Stop" 24 | 25 | $helper_def = @" 26 | using System.Diagnostics; 27 | using System.IO; 28 | using System.Threading; 29 | 30 | namespace Ansible.Shell 31 | { 32 | public class ProcessUtil 33 | { 34 | public static void GetProcessOutput(StreamReader stdoutStream, StreamReader stderrStream, out string stdout, out string stderr) 35 | { 36 | var sowait = new EventWaitHandle(false, EventResetMode.ManualReset); 37 | var sewait = new EventWaitHandle(false, EventResetMode.ManualReset); 38 | 39 | string so = null, se = null; 40 | 41 | ThreadPool.QueueUserWorkItem((s)=> 42 | { 43 | so = stdoutStream.ReadToEnd(); 44 | sowait.Set(); 45 | }); 46 | 47 | ThreadPool.QueueUserWorkItem((s) => 48 | { 49 | se = stderrStream.ReadToEnd(); 50 | sewait.Set(); 51 | }); 52 | 53 | foreach(var wh in new WaitHandle[] { sowait, sewait }) 54 | wh.WaitOne(); 55 | 56 | stdout = so; 57 | stderr = se; 58 | } 59 | } 60 | } 61 | "@ 62 | 63 | $parsed_args = Parse-Args $args $false 64 | 65 | $raw_command_line = $(Get-AnsibleParam $parsed_args "_raw_params" -failifempty $true).Trim() 66 | $chdir = Get-AnsibleParam $parsed_args "chdir" 67 | $executable = Get-AnsibleParam $parsed_args "executable" 68 | $creates = Get-AnsibleParam $parsed_args "creates" 69 | $removes = Get-AnsibleParam $parsed_args "removes" 70 | 71 | $result = @{changed=$true; warnings=@(); cmd=$raw_command_line} 72 | 73 | If($creates -and $(Test-Path $creates)) { 74 | Exit-Json @{cmd=$raw_command_line; msg="skipped, since $creates exists"; changed=$false; skipped=$true; rc=0} 75 | } 76 | 77 | If($removes -and -not $(Test-Path $removes)) { 78 | Exit-Json @{cmd=$raw_command_line; msg="skipped, since $removes does not exist"; changed=$false; skipped=$true; rc=0} 79 | } 80 | 81 | Add-Type -TypeDefinition $helper_def 82 | 83 | $exec_args = $null 84 | 85 | If(-not $executable -or $executable -eq "powershell") { 86 | $exec_application = "powershell" 87 | 88 | # Base64 encode the command so we don't have to worry about the various levels of escaping 89 | $encoded_command = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($raw_command_line)) 90 | 91 | $exec_args = @("-noninteractive", "-encodedcommand", $encoded_command) 92 | } 93 | Else { 94 | # FUTURE: support arg translation from executable (or executable_args?) to process arguments for arbitrary interpreter? 95 | $exec_application = $executable 96 | $exec_args = @("/c", $raw_command_line) 97 | } 98 | 99 | $proc = New-Object System.Diagnostics.Process 100 | $psi = $proc.StartInfo 101 | $psi.FileName = $exec_application 102 | $psi.Arguments = $exec_args 103 | $psi.RedirectStandardOutput = $true 104 | $psi.RedirectStandardError = $true 105 | $psi.UseShellExecute = $false 106 | 107 | If ($chdir) { 108 | $psi.WorkingDirectory = $chdir 109 | } 110 | 111 | $start_datetime = [DateTime]::UtcNow 112 | 113 | Try { 114 | $proc.Start() | Out-Null # will always return $true for non shell-exec cases 115 | } 116 | Catch [System.ComponentModel.Win32Exception] { 117 | # fail nicely for "normal" error conditions 118 | # FUTURE: this probably won't work on Nano Server 119 | $excep = $_ 120 | Exit-Json @{failed=$true;changed=$false;cmd=$raw_command_line;rc=$excep.Exception.NativeErrorCode;msg=$excep.Exception.Message} 121 | } 122 | 123 | $stdout = $stderr = [string] $null 124 | 125 | [Ansible.Shell.ProcessUtil]::GetProcessOutput($proc.StandardOutput, $proc.StandardError, [ref] $stdout, [ref] $stderr) | Out-Null 126 | 127 | $result.stdout = $stdout 128 | $result.stderr = $stderr 129 | 130 | # TODO: decode CLIXML stderr output (and other streams?) 131 | 132 | $proc.WaitForExit() | Out-Null 133 | 134 | $result.rc = $proc.ExitCode 135 | 136 | $end_datetime = [DateTime]::UtcNow 137 | 138 | $result.start = $start_datetime.ToString("yyyy-MM-dd hh:mm:ss.ffffff") 139 | $result.end = $end_datetime.ToString("yyyy-MM-dd hh:mm:ss.ffffff") 140 | $result.delta = $($end_datetime - $start_datetime).ToString("h\:mm\:ss\.ffffff") 141 | 142 | Exit-Json $result 143 | -------------------------------------------------------------------------------- /windows/win_shell.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # (c) 2016, Ansible, 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 | ANSIBLE_METADATA = {'status': ['preview'], 23 | 'supported_by': 'core', 24 | 'version': '1.0'} 25 | 26 | DOCUMENTATION = ''' 27 | --- 28 | module: win_shell 29 | short_description: Execute shell commands on target hosts. 30 | version_added: 2.2 31 | description: 32 | - The M(win_shell) module takes the command name followed by a list of space-delimited arguments. 33 | It is similar to the M(win_command) module, but runs 34 | the command via a shell (defaults to PowerShell) on the target host. 35 | options: 36 | free_form: 37 | description: 38 | - the win_shell module takes a free form command to run. There is no parameter actually named 'free form'. 39 | See the examples! 40 | required: true 41 | creates: 42 | description: 43 | - a path or path filter pattern; when the referenced path exists on the target host, the task will be skipped. 44 | removes: 45 | description: 46 | - a path or path filter pattern; when the referenced path B(does not) exist on the target host, the task will be skipped. 47 | chdir: 48 | description: 49 | - set the specified path as the current working directory before executing a command 50 | executable: 51 | description: 52 | - change the shell used to execute the command (eg, C(cmd)). The target shell must accept a C(/c) parameter followed by the raw command line to be executed. 53 | notes: 54 | - If you want to run an executable securely and predictably, it may be 55 | better to use the M(win_command) module instead. Best practices when writing 56 | playbooks will follow the trend of using M(win_command) unless M(win_shell) is 57 | explicitly required. When running ad-hoc commands, use your best judgement. 58 | - WinRM will not return from a command execution until all child processes created have exited. Thus, it is not possible to use win_shell to spawn long-running child or background processes. 59 | Consider creating a Windows service for managing background processes. 60 | author: 61 | - Matt Davis 62 | ''' 63 | 64 | EXAMPLES = ''' 65 | # Execute a command in the remote shell; stdout goes to the specified 66 | # file on the remote. 67 | - win_shell: C:\\somescript.ps1 >> c:\\somelog.txt 68 | 69 | # Change the working directory to somedir/ before executing the command. 70 | - win_shell: C:\\somescript.ps1 >> c:\\somelog.txt chdir=c:\\somedir 71 | 72 | # You can also use the 'args' form to provide the options. This command 73 | # will change the working directory to somedir/ and will only run when 74 | # somedir/somelog.txt doesn't exist. 75 | - win_shell: C:\\somescript.ps1 >> c:\\somelog.txt 76 | args: 77 | chdir: c:\\somedir 78 | creates: c:\\somelog.txt 79 | 80 | # Run a command under a non-Powershell interpreter (cmd in this case) 81 | - win_shell: echo %HOMEDIR% 82 | args: 83 | executable: cmd 84 | register: homedir_out 85 | ''' 86 | 87 | RETURN = ''' 88 | msg: 89 | description: changed 90 | returned: always 91 | type: boolean 92 | sample: True 93 | start: 94 | description: The command execution start time 95 | returned: always 96 | type: string 97 | sample: '2016-02-25 09:18:26.429568' 98 | end: 99 | description: The command execution end time 100 | returned: always 101 | type: string 102 | sample: '2016-02-25 09:18:26.755339' 103 | delta: 104 | description: The command execution delta time 105 | returned: always 106 | type: string 107 | sample: '0:00:00.325771' 108 | stdout: 109 | description: The command standard output 110 | returned: always 111 | type: string 112 | sample: 'Clustering node rabbit@slave1 with rabbit@master ...' 113 | stderr: 114 | description: The command standard error 115 | returned: always 116 | type: string 117 | sample: 'ls: cannot access foo: No such file or directory' 118 | cmd: 119 | description: The command executed by the task 120 | returned: always 121 | type: string 122 | sample: 'rabbitmqctl join_cluster rabbit@master' 123 | rc: 124 | description: The command return code (0 means success) 125 | returned: always 126 | type: int 127 | sample: 0 128 | stdout_lines: 129 | description: The command standard output split in lines 130 | returned: always 131 | type: list of strings 132 | sample: [u'Clustering node rabbit@slave1 with rabbit@master ...'] 133 | ''' 134 | -------------------------------------------------------------------------------- /windows/win_stat.ps1: -------------------------------------------------------------------------------- 1 | #!powershell 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 | # WANT_JSON 18 | # POWERSHELL_COMMON 19 | 20 | $params = Parse-Args $args $true; 21 | 22 | function Date_To_Timestamp($start_date, $end_date) 23 | { 24 | If($start_date -and $end_date) 25 | { 26 | Write-Output (New-TimeSpan -Start $start_date -End $end_date).TotalSeconds 27 | } 28 | } 29 | 30 | $path = Get-Attr $params "path" $FALSE; 31 | If ($path -eq $FALSE) 32 | { 33 | Fail-Json (New-Object psobject) "missing required argument: path"; 34 | } 35 | 36 | $get_md5 = Get-Attr $params "get_md5" $TRUE | ConvertTo-Bool; 37 | # until we support real aliasing, get the default value from get_md5 38 | $get_checksum = Get-Attr $params "get_checksum" $get_md5 | ConvertTo-Bool; 39 | 40 | $result = New-Object psobject @{ 41 | stat = New-Object psobject 42 | changed = $false 43 | }; 44 | 45 | If (Test-Path $path) 46 | { 47 | Set-Attr $result.stat "exists" $TRUE; 48 | 49 | $info = Get-Item $path; 50 | $iscontainer = Get-Attr $info "PSIsContainer" $null; 51 | $length = Get-Attr $info "Length" $null; 52 | $extension = Get-Attr $info "Extension" $null; 53 | $attributes = Get-Attr $info "Attributes" ""; 54 | If ($info) 55 | { 56 | $accesscontrol = $info.GetAccessControl(); 57 | } 58 | Else 59 | { 60 | $accesscontrol = $null; 61 | } 62 | $owner = Get-Attr $accesscontrol "Owner" $null; 63 | $creationtime = Get-Attr $info "CreationTime" $null; 64 | $lastaccesstime = Get-Attr $info "LastAccessTime" $null; 65 | $lastwritetime = Get-Attr $info "LastWriteTime" $null; 66 | 67 | 68 | $epoch_date = Get-Date -Date "01/01/1970" 69 | If ($iscontainer) 70 | { 71 | Set-Attr $result.stat "isdir" $TRUE; 72 | } 73 | Else 74 | { 75 | Set-Attr $result.stat "isdir" $FALSE; 76 | Set-Attr $result.stat "size" $length; 77 | } 78 | Set-Attr $result.stat "extension" $extension; 79 | Set-Attr $result.stat "attributes" $attributes.ToString(); 80 | # Set-Attr $result.stat "owner" $getaccesscontrol.Owner; 81 | # Set-Attr $result.stat "owner" $info.GetAccessControl().Owner; 82 | Set-Attr $result.stat "owner" $owner; 83 | Set-Attr $result.stat "creationtime" (Date_To_Timestamp $epoch_date $creationtime); 84 | Set-Attr $result.stat "lastaccesstime" (Date_To_Timestamp $epoch_date $lastaccesstime); 85 | Set-Attr $result.stat "lastwritetime" (Date_To_Timestamp $epoch_date $lastwritetime); 86 | } 87 | Else 88 | { 89 | Set-Attr $result.stat "exists" $FALSE; 90 | } 91 | 92 | # only check get_checksum- it either got its value from get_md5 or was set directly. 93 | If (($get_checksum) -and $result.stat.exists -and -not $result.stat.isdir) 94 | { 95 | $hash = Get-FileChecksum($path); 96 | Set-Attr $result.stat "md5" $hash; 97 | Set-Attr $result.stat "checksum" $hash; 98 | } 99 | 100 | Exit-Json $result; 101 | -------------------------------------------------------------------------------- /windows/win_stat.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 | # this is a windows documentation stub, actual code lives in the .ps1 18 | # file of the same name 19 | 20 | ANSIBLE_METADATA = {'status': ['stableinterface'], 21 | 'supported_by': 'core', 22 | 'version': '1.0'} 23 | 24 | DOCUMENTATION = ''' 25 | --- 26 | module: win_stat 27 | version_added: "1.7" 28 | short_description: returns information about a Windows file 29 | description: 30 | - Returns information about a Windows file 31 | options: 32 | path: 33 | description: 34 | - The full path of the file/object to get the facts of; both forward and 35 | back slashes are accepted. 36 | required: true 37 | default: null 38 | aliases: [] 39 | get_md5: 40 | description: 41 | - Whether to return the checksum sum of the file. As of Ansible 1.9 this 42 | is no longer a MD5, but a SHA1 instead. 43 | required: false 44 | default: yes 45 | aliases: [] 46 | get_checksum: 47 | description: 48 | - Whether to return a checksum of the file 49 | (only sha1 currently supported) 50 | required: false 51 | default: yes 52 | version_added: "2.1" 53 | author: "Chris Church (@cchurch)" 54 | ''' 55 | 56 | EXAMPLES = ''' 57 | - name: Obtain information about a file 58 | win_stat: 59 | path: C:\foo.ini 60 | register: file_info 61 | 62 | - debug: 63 | var: file_info 64 | ''' 65 | 66 | -------------------------------------------------------------------------------- /windows/win_template.py: -------------------------------------------------------------------------------- 1 | # this is a virtual module that is entirely implemented server side 2 | 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 | ANSIBLE_METADATA = {'status': ['stableinterface'], 19 | 'supported_by': 'core', 20 | 'version': '1.0'} 21 | 22 | DOCUMENTATION = r''' 23 | --- 24 | module: win_template 25 | version_added: "1.9.2" 26 | short_description: Templates a file out to a remote server. 27 | description: 28 | - Templates are processed by the Jinja2 templating language 29 | (U(http://jinja.pocoo.org/docs/)) - documentation on the template 30 | formatting can be found in the Template Designer Documentation 31 | (U(http://jinja.pocoo.org/docs/templates/)). 32 | - "Six additional variables can be used in templates: C(ansible_managed) 33 | (configurable via the C(defaults) section of C(ansible.cfg)) contains a string 34 | which can be used to describe the template name, host, modification time of the 35 | template file and the owner uid, C(template_host) contains the node name of 36 | the template's machine, C(template_uid) the owner, C(template_path) the 37 | absolute path of the template, C(template_fullpath) is the absolute path of the 38 | template, and C(template_run_date) is the date that the template was rendered. Note that including 39 | a string that uses a date in the template will result in the template being marked 'changed' 40 | each time." 41 | options: 42 | src: 43 | description: 44 | - Path of a Jinja2 formatted template on the local server. This can be a relative or absolute path. 45 | required: true 46 | dest: 47 | description: 48 | - Location to render the template to on the remote machine. 49 | required: true 50 | notes: 51 | - "templates are loaded with C(trim_blocks=True)." 52 | - By default, windows line endings are not created in the generated file. 53 | - "In order to ensure windows line endings are in the generated file, add the following header 54 | as the first line of your template: ``#jinja2: newline_sequence:'\\r\\n'`` and ensure each line 55 | of the template ends with \\\\r\\\\n" 56 | - Beware fetching files from windows machines when creating templates 57 | because certain tools, such as Powershell ISE, and regedit's export facility 58 | add a Byte Order Mark as the first character of the file, which can cause tracebacks. 59 | - Use "od -cx" to examine your templates for Byte Order Marks. 60 | author: "Jon Hawkesworth (@jhawkesworth)" 61 | ''' 62 | 63 | EXAMPLES = ''' 64 | # Playbook Example 65 | - win_template: 66 | src: /mytemplates/file.conf.j2 67 | dest: C:\temp\file.conf 68 | 69 | # Ad-hoc Example 70 | ansible winhost -m win_template -a "src=/mytemplates/file.conf.j2 dest=c:/temp/file.conf" 71 | 72 | ''' 73 | -------------------------------------------------------------------------------- /windows/win_user.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # (c) 2014, Matt Martz , and others 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': ['stableinterface'], 25 | 'supported_by': 'core', 26 | 'version': '1.0'} 27 | 28 | DOCUMENTATION = ''' 29 | --- 30 | module: win_user 31 | version_added: "1.7" 32 | short_description: Manages local Windows user accounts 33 | description: 34 | - Manages local Windows user accounts 35 | options: 36 | name: 37 | description: 38 | - Name of the user to create, remove or modify. 39 | required: true 40 | fullname: 41 | description: 42 | - Full name of the user 43 | required: false 44 | default: null 45 | version_added: "1.9" 46 | description: 47 | description: 48 | - Description of the user 49 | required: false 50 | default: null 51 | version_added: "1.9" 52 | password: 53 | description: 54 | - Optionally set the user's password to this (plain text) value. 55 | required: false 56 | default: null 57 | update_password: 58 | description: 59 | - C(always) will update passwords if they differ. C(on_create) will 60 | only set the password for newly created users. 61 | required: false 62 | choices: [ 'always', 'on_create' ] 63 | default: always 64 | version_added: "1.9" 65 | password_expired: 66 | description: 67 | - C(yes) will require the user to change their password at next login. 68 | C(no) will clear the expired password flag. 69 | required: false 70 | choices: [ 'yes', 'no' ] 71 | default: null 72 | version_added: "1.9" 73 | password_never_expires: 74 | description: 75 | - C(yes) will set the password to never expire. C(no) will allow the 76 | password to expire. 77 | required: false 78 | choices: [ 'yes', 'no' ] 79 | default: null 80 | version_added: "1.9" 81 | user_cannot_change_password: 82 | description: 83 | - C(yes) will prevent the user from changing their password. C(no) will 84 | allow the user to change their password. 85 | required: false 86 | choices: [ 'yes', 'no' ] 87 | default: null 88 | version_added: "1.9" 89 | account_disabled: 90 | description: 91 | - C(yes) will disable the user account. C(no) will clear the disabled 92 | flag. 93 | required: false 94 | choices: [ 'yes', 'no' ] 95 | default: null 96 | version_added: "1.9" 97 | account_locked: 98 | description: 99 | - C(no) will unlock the user account if locked. 100 | required: false 101 | choices: [ 'no' ] 102 | default: null 103 | version_added: "1.9" 104 | groups: 105 | description: 106 | - Adds or removes the user from this comma-separated lis of groups, 107 | depending on the value of I(groups_action). When I(groups_action) is 108 | C(replace) and I(groups) is set to the empty string ('groups='), the 109 | user is removed from all groups. 110 | required: false 111 | version_added: "1.9" 112 | groups_action: 113 | description: 114 | - If C(replace), the user is added as a member of each group in 115 | I(groups) and removed from any other groups. If C(add), the user is 116 | added to each group in I(groups) where not already a member. If 117 | C(remove), the user is removed from each group in I(groups). 118 | required: false 119 | choices: [ "replace", "add", "remove" ] 120 | default: "replace" 121 | version_added: "1.9" 122 | state: 123 | description: 124 | - When C(present), creates or updates the user account. When C(absent), 125 | removes the user account if it exists. When C(query) (new in 1.9), 126 | retrieves the user account details without making any changes. 127 | required: false 128 | choices: 129 | - present 130 | - absent 131 | - query 132 | default: present 133 | aliases: [] 134 | author: 135 | - "Paul Durivage (@angstwad)" 136 | - "Chris Church (@cchurch)" 137 | ''' 138 | 139 | EXAMPLES = ''' 140 | # Ad-hoc example 141 | $ ansible -i hosts -m win_user -a "name=bob password=Password12345 groups=Users" all 142 | $ ansible -i hosts -m win_user -a "name=bob state=absent" all 143 | 144 | # Playbook example 145 | --- 146 | - name: Add a user 147 | hosts: all 148 | gather_facts: false 149 | tasks: 150 | - name: Add User 151 | win_user: 152 | name: ansible 153 | password: "@ns1bl3" 154 | groups: ["Users"] 155 | ''' 156 | --------------------------------------------------------------------------------