�
�Udac @` s^ d d l m Z m Z m Z e Z i d d 6d g d 6d d 6Z d Z d Z d d
l Z d
Z y d d
l Z e
Z Wn# e k
r� e j � Z e Z n Xd
Z y d d
l Z e
Z Wn# e k
r� e j � Z e Z n Xd d l m Z m Z d d l m Z e d
� Z d � Z d � Z d d d � Z d d � Z d � Z e d k rZe � n d
S( i ( t absolute_importt divisiont print_functions 1.1t metadata_versiont previewt statust communityt supported_byse
---
module: seport
short_description: Manages SELinux network port type definitions
description:
- Manages SELinux network port type definitions.
version_added: "2.0"
options:
ports:
description:
- Ports or port ranges.
- Can be a list (since 2.6) or comma separated string.
type: list
required: true
proto:
description:
- Protocol for the specified port.
type: str
required: true
choices: [ tcp, udp ]
setype:
description:
- SELinux type for the specified port.
type: str
required: true
state:
description:
- Desired boolean value.
type: str
choices: [ absent, present ]
default: present
reload:
description:
- Reload SELinux policy after commit.
type: bool
default: yes
ignore_selinux_state:
description:
- Run independent of selinux runtime state
type: bool
default: no
version_added: '2.8'
notes:
- The changes are persistent across reboots.
- Not tested on any debian based system.
requirements:
- libselinux-python
- policycoreutils-python
author:
- Dan Keder (@dankeder)
sm
- name: Allow Apache to listen on tcp port 8888
seport:
ports: 8888
proto: tcp
setype: http_port_t
state: present
- name: Allow sshd to listen on tcp port 8991
seport:
ports: 8991
proto: tcp
setype: ssh_port_t
state: present
- name: Allow memcached to listen on tcp ports 10000-10100 and 10112
seport:
ports: 10000-10100,10112
proto: tcp
setype: memcache_port_t
state: present
- name: Allow memcached to listen on tcp ports 10000-10100 and 10112
seport:
ports:
- 10000-10100
- 10112
proto: tcp
setype: memcache_port_t
state: present
N( t
AnsibleModulet missing_required_lib( t to_nativec C` s | t k r t St j � S( N( t Truet selinuxt is_selinux_enabled( t ignore_selinux_state( ( sA /usr/lib/python2.7/site-packages/ansible/modules/system/seport.pyt get_runtime_statusx s c C` s4 | j � } | | f | k r, | | | f Sg Sd S( sF Get the list of ports that have the specified type definition.
:param seport: Instance of seobject.portRecords
:type setype: str
:param setype: SELinux type.
:type proto: str
:param proto: Protocol ('tcp' or 'udp')
:rtype: list
:return: List of ports that have the specified SELinux type.
N( t get_all_by_type( t seportt setypet protot records( ( sA /usr/lib/python2.7/site-packages/ansible/modules/system/seport.pyt semanage_port_get_ports| s c C` s | j d d � } t | � d k r4 | j | � n t | d � t | d � | f } | j � } | | k rw | | Sd Sd S( sk Get the SELinux type of the specified port.
:param seport: Instance of seobject.portRecords
:type port: str
:param port: Port or port range (example: "8080", "8080-9090")
:type proto: str
:param proto: Protocol ('tcp' or 'udp')
:rtype: tuple
:return: Tuple containing the SELinux type and MLS/MCS level, or None if not found.
t -i i N( t splitt lent extendt intt get_allt None( R t portR t portst keyR ( ( sA /usr/lib/python2.7/site-packages/ansible/modules/system/seport.pyt semanage_port_get_type� s #t s0t c
C` s) y� t j | � } | j | � t } t | | | � } x� | D]� }
|
| k r>