Ansible module to manage configuration of Foreman
Python
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
module_utils Create common module_utils directory for shared code Jun 29, 2018
.gitignore Add .idea to .gitignore Sep 20, 2016
README.md Merge branch 'master' into host_interfaces Aug 2, 2018
__init__.py Add __init__.py Aug 30, 2016
foreman_architecture.py Fix imports Dec 19, 2016
foreman_compute_attribute.py compute_resource_attribute: fix error message Jul 3, 2017
foreman_compute_profile.py Fix imports Dec 19, 2016
foreman_compute_resource.py add locations and organizations to subnet, remove empty spaces in com… Apr 18, 2017
foreman_config_template.py foreman_config_template: add organization and location support Jun 29, 2018
foreman_domain.py add location and organizations to a foreman_domain Apr 18, 2017
foreman_environment.py remove debugging artefacts from testing Apr 18, 2017
foreman_external_usergroup.py Manage external usergroups Sep 11, 2017
foreman_filter.py Allow to onfigure filters May 9, 2017
foreman_global_parameter.py ADD foreman_global_parameter module. Jun 13, 2018
foreman_host.py Merge branch 'master' into master Aug 2, 2018
foreman_hostgroup.py hostgroup: don't log password Jul 4, 2017
foreman_image.py Fix imports Dec 19, 2016
foreman_ldap.py Fix imports Dec 19, 2016
foreman_location.py Fix imports Dec 19, 2016
foreman_medium.py Final changes Apr 13, 2017
foreman_operatingsystem.py operatingsystem: look for os minor version as well Jul 3, 2017
foreman_organization.py Fix imports Dec 19, 2016
foreman_os_default_template.py Fix imports Dec 19, 2016
foreman_ptable.py Fix imports Dec 19, 2016
foreman_realm.py Fix imports Dec 19, 2016
foreman_role.py Fix imports Dec 19, 2016
foreman_setting.py settings: implement check mode Oct 4, 2017
foreman_smart_proxy.py Fix imports Dec 19, 2016
foreman_subnet.py add locations and organizations to subnet, remove empty spaces in com… Apr 18, 2017
foreman_user.py Set a proper default for admin Aug 21, 2017
foreman_usergroup.py Manage usergroups Sep 1, 2017

README.md

Ansible library Foreman

Table of Contents

Description

Ansible library to configure Foreman and manage hosts.

With the current implementation it's possible to create, update and delete the following Foreman Resources

  • Architectures
  • Compute Attributes
  • Compute Profiles
  • Compute Resources
  • Config Templates
  • Domains
  • Environments
  • Hosts
  • Hostgroups
  • Locations (needs Katello)
  • Medium
  • Operatingsystems
  • Operatingsystem default templates
  • Organizations (need s Katello)
  • Partition Tables
  • Roles
  • Smart Proxies
  • Subnets
  • Users

Requirements

python-foreman >= 0.12.11 is required to be installed on the system where Ansible is started from.

Examples

ansible.cfg has to contain path to modules and module_utils:

[default]
library = ansible-module-foreman
module_utils = ansible-module-foreman/module_utils

The following parameters are always required so the module knows how to connect to the Foreman API v2. They are replaced in the examples by three dots (...).

foreman_host: foreman.example.com
foreman_port: 443
foreman_user: admin
foreman_pass: password

Architecture

- name: Ensure Architecture
  foreman_architecture:
    name: x86_64
    state: present
    foreman_host: foreman.example.com
    foreman_port: 443
    foreman_user: admin
    foreman_pass: password

Compute Profile

- name: Ensure Compute Profile
  foreman_compute_profile:
    name: 1-Small
    foreman_host: foreman.example.com
    foreman_port: 443
    foreman_user: admin
    foreman_pass: password

Compute Resource

- name: Ensure Compute Resource
  foreman_compute_resource:
    name: VMwareCluster01
    state: present
    url: vsphere.example.com
    provider: VMWare
    user: ansible
    password: secret
    server: vsphere.example.com
    ...

Compute Attribute

This is an example to configure VMware vSphere attributes.

- name: Ensure Compute Attribute
  foreman_compute_attribute:
    compute_profile: 1-Small
    compute_resource: VMwareCluster1
    vm_attributes:
      cluster: Cluster1
      corespersocket: 1
      cpus: 1
      guest_id: otherGuest64
      hardware_version: vmx-10
      interfaces_attributes:
      '0':
        _delete: ''
        network: network-40
        type: VirtualVmxnet3
      '1':
        _delete: ''
        network: network-40
        type: VirtualVmxnet3
      new_interfaces:
        _delete: ''
        network: network-40
        type: VirtualVmxnet3
        memory_mb: 1024
      path: /Datacenters/DC01/vm/example
      scsi_controller_type: ParaVirtualSCSIController
      volumes_attributes:
        '0':
          _delete: ''
          datastore: DS01
          eager_zero: true
          name: Hard disk
          size_gb: 16
          thin: true
        new_volumes:
          _delete: ''
          datastore: DS01
          eager_zero: true
          name: Hard disk
          size_gb: 16
          thin: true
    ...

Config Template

Deploy existing file

- name: Ensure Config Template
  foreman_config_template:
    name: CoreOS Cloud-config
    locked: false
    operatingsystems:
    - CoreOS
    template_file: files/coreos-cloud-config
    snippet: true
    state: present
    ...

Deploy content

- name: Ensure Config Template
  foreman_config_template:
    name: CoreOS Cloud-config
    locked: false
    operatingsystems:
    - CoreOS
    template: "Some content"
    snippet: true
    state: present
...

Domain

- name: Ensure Domain
  foreman_domain:
    name: example.com
    state: present
    ...

Environments

- name: Ensure Environment
  foreman_environment:
    name: Production
    state: present
    ...

Host

Provision using installation from medium

- name: Ensure Host
  foreman_host:
    name: ansible-host-01
    state: running
    architecture: x86_64
    domain: example.com
    environment: production
    medium: CoreOS
    provision_method: build
    root_pass: topsecret

Provision by clone from image

- name: Ensure Host
  foreman_host:
    name: ansible-host-03
    state: running
    compute_resource: VMwareCluster01
    hostgroup: Hostgroup01
    image: CoreOS Image
    provision_method: image
...

Provision using a hostgroup

- name: Ensure Host
  foreman_host:
    name: ansible-host-02
    state: running
    compute_resource: VMwareCluster01
    hostgroup: Hostgroup01
    provision_method: build
    ...

Delete host

To delete a host Foreman must know the FQDN. Use one of the following methods:

- name: Ensure absent host
  foreman_host:
    name: ansible-host-01
    domain: example.com
    state: absent
    ...

or

- name: Ensure absent host
  foreman_host:
    name: ansible-host-01.example.com
    state: absent
...

Host with network interfaces

- name: Ensure Host
  foreman_host:
    name: ansible-host-04
    state: present
    .
    .
    interfaces:
      - ip: 10.11.12.123
        mac: 00:21:f6:16:e4:2e
        subnet: "Dev Network"
      - ip: 10.11.12.124
        mac: 00:21:f6:42:52:91
        subnet: "Dev Network"
    ...

Hostgroup

- name: Ensure Hostgroup
  foreman_hostgroup:
    name: Hostgroup01
    architecture: x86_64
    domain: example.com
    environment: production
    medium: CoreOS mirror
    operatingsystem: CoreOS
    partition_table: CoreOS Partition Table
    subnet: example.com
    state: present
    ...

Location

- name: Ensure Location
  foreman_location:
    name: Location01
    state: present
    ...

Medium

- name: Ensure Medium
  foreman_medium:
    name: CoreOS
    path: http://$release.release.core-os.net
    os_family: CoreOS
    state: present
    ...

Operatingsystem

- name: Ensure Operatingsystem
  foreman_operatingsystem:
    name: CoreOS
    major: 633
    minor: 0.0
    architectures:
    - x86_64
    media:
    - CoreOS mirror
    ptables:
    - CoreOS default fake
    state: present
  ...

Operatingsystem default template

- name: Ensure Operatingsystem default template
  foreman_os_default_template:
    operatingsystem: CoreOS
    config_template: CoreOS PXELinux
    template_kind: PXELinux
    state: present
    ...

Organization

Works only if Katello is used

- name: Ensure Organization
  foreman_organization:
    name: MyOrganization
    state: present
    ...

Partition Table

- name: Ensure partition table
  foreman_ptable:
    name: MyPartitionTable
    layout: 'some layout'
    os_family: CoreOS
    state: present
    ...

Role

- name: Ensure Role
  foreman_role:
    name: MyRole
    state: present

Smart Proxy

- name: Ensure Smart Proxy
  foreman_smart_proxy:
    name: SmartProxy01
    url: http://localhost:8443
    state: present
    ...

User

- name: Ensure User
  foreman_user:
    login: MyUser
    admin: false
    auth: 'Internal'
    firstname: Testing
    lastname: User
    mail: testing.user@example.com
    password: topsecret
    roles:
    - Manager
    - Viewer
    state: present

License

Copyright 2015 Thomas Krahn

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

Thomas Krahn