controller_configuration
controller_configuration copied to clipboard
controller_templates missing example, can't get it to work
Hi,
I have been banging my head to a problem of how to define execution_environment for controller_template.
If I take out a template from AAP2.1 using the awx collection, it looks like this:
---
assets:
job_templates:
- allow_simultaneous: false
ask_credential_on_launch: false
ask_diff_mode_on_launch: false
ask_inventory_on_launch: false
ask_job_type_on_launch: false
ask_limit_on_launch: false
ask_scm_branch_on_launch: false
ask_skip_tags_on_launch: false
ask_tags_on_launch: false
ask_variables_on_launch: false
ask_verbosity_on_launch: true
become_enabled: false
description: ''
diff_mode: false
execution_environment:
name: cool-lab-community
type: execution_environment
extra_vars: "---\nansible_python_interpreter:\
\ /bin/python3\nnet_name: RH-seg-2991\n\
net_type: dhcp\nmemory_mb: 2048\nnum_cpus:\
\ 2\nstate: poweredon\n# state: absent\n\
vm_name: rh-deleteme-01\nvcenter_credentials:\n\
\ hostname: '{{ lookup(\"env\", \"VMWARE_HOST\"\
) }}'\n username: '{{ lookup(\"env\", \"\
VMWARE_USER\") }}'\n password: '{{ lookup(\"\
env\", \"VMWARE_PASSWORD\") }}'\nuse_aap_inventory:\
\ true"
force_handlers: false
forks: 0
host_config_key: ''
inventory:
name: Demo Inventory
organization:
name: Default
type: organization
type: inventory
job_slice_count: 1
job_tags: ''
job_type: run
limit: localhost
name: test-vm
natural_key:
name: test-vm
organization:
name: rhops
type: organization
type: job_template
playbook: ensure-vm-state.yml
project:
name: Cool-Lab ikke-test
organization:
name: rhops
type: organization
type: project
related:
credentials:
- credential_type:
kind: cloud
name: Red Hat Ansible Automation
Platform
type: credential_type
name: aap-creds-rhops-admin
organization:
name: rhops
type: organization
type: credential
- credential_type:
kind: cloud
name: VMware vCenter
type: credential_type
name: vcenter-21
organization:
name: rhops
type: organization
type: credential
labels: []
notification_templates_error: []
notification_templates_started: []
notification_templates_success: []
schedules: []
survey_spec:
description: ''
name: ''
spec:
- choices: ''
default: ''
formattedChoices:
- choice: ''
id: 0
isDefault: false
max: 1024
min: 1
new_question: false
question_description: short name
for the hostname. Use format
rh-<whatever>-<number>, e.g.
rh-ikketest-10
question_name: Host Name
required: true
type: text
variable: short_name
- choices: 'RH-seg-2990
RH-seg-2991
RH-seg-2992
RH-seg-2993'
default: RH-seg-2991
max: 1024
min: 0
new_question: true
question_description: Into which
wlan the VM goes.
question_name: VLAN name
required: true
type: multiplechoice
variable: net_name
- choices: '512
1024
2048
4096
8192
16384
32768
65536'
default: '4096'
max: 65536
min: 512
new_question: true
question_description: How much RAM
in megabytes
question_name: Memory MB
required: true
type: multiplechoice
variable: memory_mb
- choices: '1
2
4
8
16'
default: '2'
max: 1024
min: 0
new_question: true
question_description: How many CPU
question_name: CPU
required: true
type: multiplechoice
variable: num_cpu
- choices: 'poweredon
poweredoff
absent'
default: poweredon
max: 1024
min: 0
new_question: true
question_description: poweredon/off/absent
question_name: VM state
required: true
type: multiplechoice
variable: state
scm_branch: ''
skip_tags: ''
start_at_task: ''
survey_enabled: true
timeout: 0
use_fact_cache: false
verbosity: 0
webhook_credential: null
webhook_service: ''
If I try feeding that back to AAP by using the controller_template, with execution env like it was above:
controller_templates:
- name: ensure-vm
description: 'Creates of deletes a VM, or sets state to powered off'
allow_simultaneous: false
ask_credential_on_launch: false
ask_diff_mode_on_launch: false
ask_inventory_on_launch: false
ask_job_type_on_launch: false
ask_limit_on_launch: false
ask_scm_branch_on_launch: false
ask_skip_tags_on_launch: false
ask_tags_on_launch: false
ask_variables_on_launch: false
ask_verbosity_on_launch: false
become_enabled: false
diff_mode: false
execution_environment:
name: 'cool-lab-community'
type: 'execution_environment'
extra_vars:
ansible_python_interpreter: /bin/python3
net_name: RH-seg-2991
net_type: dhcp
memory_mb: 2048
num_cpus: 2
state: poweredon
name: rh-cntrl-test-01
vcenter_credentials:
hostname: '{{ lookup("env", "VMWARE_HOST") }}'
username: '{{ lookup("env", "VMWARE_USER") }}'
password: '{{ lookup("env", "VMWARE_PASSWORD") }}'
force_handlers: false
forks: 0
host_config_key: ''
inventory:
name: Demo Inventory
organization:
name: Default
type: organization
type: inventory
job_slice_count: 1
job_tags: ''
job_type: run
limit: localhost
natural_key:
name: test-vm
organization:
name: rhops
type: organization
type: job_template
playbook: ensure-vm-state.yml
project:
name: Cool-Lab ikke-test
organization:
name: rhops
type: organization
type: project
related:
credentials:
- credential_type:
kind: cloud
name: VMware vCenter
type: credential_type
name: vcenter-21
organization:
name: rhops
type: organization
type: credential
labels: []
notification_templates_error: []
notification_templates_started: []
notification_templates_success: []
schedules: []
survey_spec:
description: ''
name: ''
spec:
- choices: ''
default: ''
max: 1024
min: 1
new_question: true
question_description: short name
for the hostname. Use format
rh-<whatever>-<number>, e.g.
rh-ikketest-10
question_name: Host Name
required: true
type: text
variable: name
- choices: 'RH-seg-2990
RH-seg-2991
RH-seg-2992
RH-seg-2993'
default: RH-seg-2991
max: 1024
min: 0
new_question: true
question_description: Into which
wlan the VM goes.
question_name: VLAN name
required: true
type: multiplechoice
variable: net_name
- choices: '512
1024
2048
4096
8192
16384
32768
65536'
default: '4096'
max: 65536
min: 512
new_question: true
question_description: How much RAM
in megabytes
question_name: Memory MB
required: true
type: multiplechoice
variable: memory_mb
- choices: '1
2
4
8
16'
default: '2'
max: 1024
min: 0
new_question: true
question_description: How many CPU
question_name: CPU
required: true
type: multiplechoice
variable: num_cpu
- choices: 'poweredon
poweredoff
absent'
default: poweredon
max: 1024
min: 0
new_question: true
question_description: poweredon/off/absent
question_name: VM state
required: true
type: multiplechoice
variable: state
scm_branch: ''
skip_tags: ''
start_at_task: ''
survey_enabled: true
timeout: 0
use_fact_cache: false
verbosity: 0
webhook_credential: null
webhook_service: ''
It complains about execution_envs:
[WARNING]: The value {'name': 'cool-lab-community', 'type': 'execution_environment'} (type dict) in a string field was converted to "{'name': 'cool-
lab-community', 'type': 'execution_environment'}" (type string). If this does not look like what you expect, quote the entire value to ensure it does
not change.
[WARNING]: You are using the awx version of this collection but connecting to Red Hat Ansible Automation Platform
failed: [localhost] (item={'name': 'ensure-vm', 'description': 'Creates of deletes a VM, or sets state to powered off', 'allow_simultaneous': False, 'ask_credential_on_launch': False, 'ask_diff_mode_on_launch': False, 'ask_inventory_on_launch': False, 'ask_job_type_on_launch': False, 'ask_limit_on_launch': False, 'ask_scm_branch_on_launch': False, 'ask_skip_tags_on_launch': False, 'ask_tags_on_launch': False, 'ask_variables_on_launch': False, 'ask_verbosity_on_launch': False, 'become_enabled': False, 'diff_mode': False, 'execution_environment': {'name': 'cool-lab-community', 'type': 'execution_environment'}, 'extra_vars': {'ansible_python_interpreter': '/bin/python3', 'net_name': 'RH-seg-2991', 'net_type': 'dhcp', 'memory_mb': 2048, 'num_cpus': 2, 'state': 'poweredon', 'name': 'rh-cntrl-test-01', 'vcenter_credentials': {'hostname': '', 'username': '', 'password': ''}}, 'force_handlers': False, 'forks': 0, 'host_config_key': '', 'inventory': {'name': 'Demo Inventory', 'organization': {'name': 'Default', 'type': 'organization'}, 'type': 'inventory'}, 'job_slice_count': 1, 'job_tags': '', 'job_type': 'run', 'limit': 'localhost', 'natural_key': {'name': 'test-vm', 'organization': {'name': 'rhops', 'type': 'organization'}, 'type': 'job_template'}, 'playbook': 'ensure-vm-state.yml', 'project': {'name': 'Cool-Lab ikke-test', 'organization': {'name': 'rhops', 'type': 'organization'}, 'type': 'project'}, 'related': {'credentials': [{'credential_type': {'kind': 'cloud', 'name': 'VMware vCenter', 'type': 'credential_type'}, 'name': 'vcenter-21', 'organization': {'name': 'rhops', 'type': 'organization'}, 'type': 'credential'}], 'labels': [], 'notification_templates_error': [], 'notification_templates_started': [], 'notification_templates_success': [], 'schedules': [], 'survey_spec': {'description': '', 'name': '', 'spec': [{'choices': '', 'default': '', 'max': 1024, 'min': 1, 'new_question': True, 'question_description': 'short name for the hostname. Use format rh-<whatever>-<number>, e.g. rh-ikketest-10', 'question_name': 'Host Name', 'required': True, 'type': 'text', 'variable': 'name'}, {'choices': 'RH-seg-2990\nRH-seg-2991\nRH-seg-2992\nRH-seg-2993', 'default': 'RH-seg-2991', 'max': 1024, 'min': 0, 'new_question': True, 'question_description': 'Into which wlan the VM goes.', 'question_name': 'VLAN name', 'required': True, 'type': 'multiplechoice', 'variable': 'net_name'}, {'choices': '512\n1024\n2048\n4096\n8192\n16384\n32768\n65536', 'default': '4096', 'max': 65536, 'min': 512, 'new_question': True, 'question_description': 'How much RAM in megabytes', 'question_name': 'Memory MB', 'required': True, 'type': 'multiplechoice', 'variable': 'memory_mb'}, {'choices': '1\n2\n4\n8\n16', 'default': '2', 'max': 1024, 'min': 0, 'new_question': True, 'question_description': 'How many CPU', 'question_name': 'CPU', 'required': True, 'type': 'multiplechoice', 'variable': 'num_cpu'}, {'choices': 'poweredon\npoweredoff\nabsent', 'default': 'poweredon', 'max': 1024, 'min': 0, 'new_question': True, 'question_description': 'poweredon/off/absent', 'question_name': 'VM state', 'required': True, 'type': 'multiplechoice', 'variable': 'state'}]}}, 'scm_branch': '', 'skip_tags': '', 'start_at_task': '', 'survey_enabled': True, 'timeout': 0, 'use_fact_cache': False, 'verbosity': 0, 'webhook_credential': None, 'webhook_service': ''}) => {"__controller_template_item": {"allow_simultaneous": false, "ask_credential_on_launch": false, "ask_diff_mode_on_launch": false, "ask_inventory_on_launch": false, "ask_job_type_on_launch": false, "ask_limit_on_launch": false, "ask_scm_branch_on_launch": false, "ask_skip_tags_on_launch": false, "ask_tags_on_launch": false, "ask_variables_on_launch": false, "ask_verbosity_on_launch": false, "become_enabled": false, "description": "Creates of deletes a VM, or sets state to powered off", "diff_mode": false, "execution_environment": {"name": "cool-lab-community", "type": "execution_environment"}, "extra_vars": {"ansible_python_interpreter": "/bin/python3", "memory_mb": 2048, "name": "rh-cntrl-test-01", "net_name": "RH-seg-2991", "net_type": "dhcp", "num_cpus": 2, "state": "poweredon", "vcenter_credentials": {"hostname": "", "password": "", "username": ""}}, "force_handlers": false, "forks": 0, "host_config_key": "", "inventory": {"name": "Demo Inventory", "organization": {"name": "Default", "type": "organization"}, "type": "inventory"}, "job_slice_count": 1, "job_tags": "", "job_type": "run", "limit": "localhost", "name": "ensure-vm", "natural_key": {"name": "test-vm", "organization": {"name": "rhops", "type": "organization"}, "type": "job_template"}, "playbook": "ensure-vm-state.yml", "project": {"name": "Cool-Lab ikke-test", "organization": {"name": "rhops", "type": "organization"}, "type": "project"}, "related": {"credentials": [{"credential_type": {"kind": "cloud", "name": "VMware vCenter", "type": "credential_type"}, "name": "vcenter-21", "organization": {"name": "rhops", "type": "organization"}, "type": "credential"}], "labels": [], "notification_templates_error": [], "notification_templates_started": [], "notification_templates_success": [], "schedules": [], "survey_spec": {"description": "", "name": "", "spec": [{"choices": "", "default": "", "max": 1024, "min": 1, "new_question": true, "question_description": "short name for the hostname. Use format rh-<whatever>-<number>, e.g. rh-ikketest-10", "question_name": "Host Name", "required": true, "type": "text", "variable": "name"}, {"choices": "RH-seg-2990\nRH-seg-2991\nRH-seg-2992\nRH-seg-2993", "default": "RH-seg-2991", "max": 1024, "min": 0, "new_question": true, "question_description": "Into which wlan the VM goes.", "question_name": "VLAN name", "required": true, "type": "multiplechoice", "variable": "net_name"}, {"choices": "512\n1024\n2048\n4096\n8192\n16384\n32768\n65536", "default": "4096", "max": 65536, "min": 512, "new_question": true, "question_description": "How much RAM in megabytes", "question_name": "Memory MB", "required": true, "type": "multiplechoice", "variable": "memory_mb"}, {"choices": "1\n2\n4\n8\n16", "default": "2", "max": 1024, "min": 0, "new_question": true, "question_description": "How many CPU", "question_name": "CPU", "required": true, "type": "multiplechoice", "variable": "num_cpu"}, {"choices": "poweredon\npoweredoff\nabsent", "default": "poweredon", "max": 1024, "min": 0, "new_question": true, "question_description": "poweredon/off/absent", "question_name": "VM state", "required": true, "type": "multiplechoice", "variable": "state"}]}}, "scm_branch": "", "skip_tags": "", "start_at_task": "", "survey_enabled": true, "timeout": 0, "use_fact_cache": false, "verbosity": 0, "webhook_credential": null, "webhook_service": ""}, "ansible_loop_var": "__controller_template_item", "changed": false, "msg": "Request to /api/v2/execution_environments/?name=%7B%27name%27%3A+%27cool-lab-community%27%2C+%27type%27%3A+%27execution_environment%27%7D returned 0 items, expected 1", "query": {"name": "{'name': 'cool-lab-community', 'type': 'execution_environment'}"}, "response": {"json": {"count": 0, "next": null, "previous": null, "results": []}, "status_code": 200}, "total_results": 0}
the above one has ident inconsistency later on the file, I have fixed it. Such has no effect. Breaks the same
thanks for @sean-m-sullivan helping me out with this, so it works if I do:
execution_enviroment: cool-lab-community
this fix should be in 2.1.4, I will leave this issue open until the READMEs have been updated
Looking at the actual line of code that adds the execution environment, it seems that the original example would now work based on the export method:
https://github.com/redhat-cop/controller_configuration/blob/ad679a4481e79afbc36b948cb76e6e80b9acd13f/roles/job_templates/tasks/main.yml#L9
I've also raised a PR which adds in to the example the execution_environment option.