cancel
Showing results for 
Search instead for 
Did you mean: 
smi-andrew
Flight Engineer
Flight Engineer
  • 542 Views

Controller schedule job help

Jump to solution

I currently have a ansible role I am working on that does os_patching for us. In that role I need **bleep** to take snapshots and then create a scheduled job in AAP to remove those snapshots after 1 week. I’ve got most of this working using the vmware.vmware or vmware_rest collections. Right now I’m running into an issue with the ansible.controller.schedule module. I am aware of the set_fact statement that has a date WAY in the past. My main issue comes down to making the rrule work. This seems to be where the role fails in my AAP instance and I’m not understanding why.

Here is the code I have written:

- name: Calculate 'DTSTART' 7 days in the future using shell
  ansible.builtin.shell: |
    date -d "+7 days"
  register: future_rrule_shell
  delegate_to: localhost

- name: Set 'dynamic_rrule' fact from shell output
  ansible.builtin.set_fact:
    dynamic_rrule: "{{ future_rrule_shell.stdout }}"

- name: Create a ruleset for everyday except Sundays
  ansible.builtin.set_fact:
    complex_rule: "{{ lookup(awx.awx.schedule_rruleset, '2022-04-30 10:30:45', rules=rrules, timezone='UTC' ) }}"
  vars:
    rrules:
    - frequency: 'day'
      interval: 1
    - frequency: 'day'
      interval: 1
      byweekday: 'sunday'
      include: False

- name: Schedule a one-time snapshot cleanup in AAP (T+{{ snapshot_ttl_days|default(7) }} days)
  ansible.controller.schedule:
    controller_host: "{{ lookup ('env', 'CONTROLLER_HOST') }}"
    controller_username: "{{ lookup ('env', 'CONTROLLER_USERNAME') }}"
    controller_password: "{{ lookup ('env', 'CONTROLLER_PASSWORD') }}"
    validate_certs: "{{ controller_validate_certs | default(true) }}"
    enabled: true
    job_type: run
    unified_job_template: vmware_snapshot_cleanup # your JobTemplate name
    name: "Cleanup {{ vm_name | default(inventory_hostname_short) }} pre-change on {{ selected_aap_instance.name }}"
    rrule: "DTSTART:{{ dynamic_rrule }}"
    #extra_data:
    #  vcenter_hostname: "{{ _chosen_vcenter }}"
    #  vcenter_username: "{{ vcenter_username }}"
    #  vcenter_password: "{{ vcenter_password }}"
    #  vcenter_validate_certs: "{{ vcenter_validate_certs | default(false) }}"
    #  vm_id: "{{ _vm_id }}"
  delegate_to: localhost

Here is the output from AAP.

 

 
[ERROR]: Task failed: Module failed: 'NoneType' object has no attribute 'replace'
Origin: /runner/requirements_roles/os_patching/tasks/vmware/schedule_removal.yml:64:3
62     dynamic_rrule: "{{ future_rrule_shell.stdout }}"
63
64 - name: Schedule a one-time snapshot cleanup in AAP (T+{{ snapshot_ttl_days|default(7) }} days)
     ^ column 3

fatal: [testserver03.example.com -> localhost]: FAILED! => {
    "changed": false,
    "msg": "Task failed: Module failed: 'NoneType' object has no attribute 'replace'"
}
<localhost> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1762377189.6961734-301-224640049938324/ > /dev/null 2>&1 && sleep 0'

fatal: [testserver01.example -> localhost]: FAILED! => {
    "changed": false,
    "msg": "Task failed: Module failed: 'NoneType' object has no attribute 'replace'"

Any help is greatly appreciated!

Labels (3)
21 Replies
smi-andrew
Flight Engineer
Flight Engineer
  • 146 Views

If I post a reply the option for code doesn't show up until I go back and edit it.  Seems someone needs to fix that.  Please.

 

Or maybe its just me.

0 Kudos
TudorRaduta
Community Manager
Community Manager
  • 82 Views

@smi-andrew  would it be possible to send me a screenshot showing this platform behavior? I’d be happy to investigate with the vendor to understand what’s causing it.

0 Kudos
smi-andrew
Flight Engineer
Flight Engineer
  • 146 Views

Also, this is only 1 task in the order of things.  I have a previous task (vmware.yml) where I get a list of servers and only take the inventory_hostname_short and parsae through that. So i'm using that list to generate the one for the snapshot removals.  I can put that here for if you would like.

 

I ended up putting in beug options all over the snapshot_removal.yml (the one you are seeing).  And I AM getting a removal date.  I have also changed things around, since the schedule was just updating the code previously.  Where it says Look up the snapshot cleanup job template ID is now creating a NEW template from the template I created.  This seems to work, BUT when I go to add a schedule to it it fails and I get the following:

 
TASK [os_patching : Schedule a one-time snapshot cleanup in AAP for 7 days from now] ***  
3:55:26 PM
task path: /runner/requirements_roles/os_patching/tasks/vmware/schedule_removal.yml:119
[ERROR]: Task failed: Module failed: 'NoneType' object is not subscriptable

Origin: /runner/requirements_roles/os_patching/tasks/vmware/schedule_removal.yml:119:3

117   delegate_to: localhost
118
119 - name: Schedule a one-time snapshot cleanup in AAP for 7 days from now
      ^ column 3

fatal: [test01.example.com -> localhost]: FAILED! => {"changed": false, "msg": "Task failed: Module failed: 'NoneType' object is not subscriptable"}

Here is the most up to date code:

- name: Schedule a one-time snapshot cleanup in AAP for 7 days from now
  ansible.controller.schedule:
    controller_host: "https://{{ selected_aap_instance.host }}"
    controller_oauthtoken: "{{ selected_aap_instance.oauth_token }}"
    validate_certs: "{{ controller_validate_certs | default(true) }}"
    organization: MY Org
    name: "{{ schedule_job_name }}"
    rrule: "{{ dynamic_rrule }}"
    unified_job_template: "{{ cleanup_job_template_lookup.id }}"
    job_type: run
    state: present
    enabled: true
#    extra_data:
#      vms_to_cleanup: "{{ all_vms_for_cleanup }}"
  run_once: true
  delegate_to: localhost
  connection: local
0 Kudos
Travis
Moderator
Moderator
  • 129 Views

@smi-andrew -

So I am still unsure where the breakage could be and also not sure why you are having code issues with the code blocks. Tagging @TudorRaduta for that as I've experienced weirdness with the interface.

According to this, it would seem the issues are around the actual schedule creation task "

task path: /runner/requirements_roles/os_patching/tasks/vmware/schedule_removal.yml:119

 

What I would suggest doing there is basically commenting out the everything in that task except for the name and then use the debug module there and print all the variables in that task. You also might want to use variable type of debug to see what type Ansible things those variables are.

My guess is it is around the rrule or the unified job template. One thing I don't understand though too is I would think the vms_to_cleanup might be needed as variables into the Job Template that the schedule is going tto run, so you might also want to see if that is available. I'm assuming that is commented out for a reason right now and it is for testing.

Travis Michette, RHCA XIII
https://rhtapps.redhat.com/verify?certId=111-134-086
SENIOR TECHNICAL INSTRUCTOR / CERTIFIED INSTRUCTOR AND EXAMINER
Red Hat Certification + Training
smi-andrew
Flight Engineer
Flight Engineer
  • 128 Views

I commented that out to see if that was causing the error.  But it wasn't.  I'll try what you suggested and let you know.  

smi-andrew
Flight Engineer
Flight Engineer
  • 113 Views

Ok so I tried what you suggested.  The documentation needs to updated for the schedule module.  I'm getting the following error:

[ERROR]: Task failed: Module failed: Unable to create schedule Bulk Cleanup for 4 VMs - scheduled for 20251118T194709Z: {'rrule': ['This field is required.'], 'unified_job_template': ['This field is required.']}
Origin: /runner/requirements_roles/os_patching/tasks/vmware/schedule_removal.yml:119:3
117   delegate_to: localhost
118
119 - name: Schedule a one-time snapshot cleanup in AAP for 7 days from now
      ^ column 3

fatal: [testapp01.example.com -> localhost]: FAILED! => {"changed": false, "msg": "Unable to create schedule Bulk Cleanup for 4 VMs - scheduled for 20251118T194709Z: {'rrule': ['This field is required.'], 'unified_job_template': ['This field is required.']}"}
0 Kudos
smi-andrew
Flight Engineer
Flight Engineer
  • 113 Views

I'm working through this.

0 Kudos
Travis
Moderator
Moderator
  • 112 Views

I think you misunderstood what I said ... I meant for you to comment out everything which included the schedule module since you are using the debug module. That way you can see how things are evaluated. 

 

- name: Schedule a one-time snapshot cleanup in AAP for 7 days from now - Var 1
  #ansible.controller.schedule:
  ansible.builtin.debug:
    var: "{{ schedule_job_name | type_debug }}"
    #controller_host: "https://{{ selected_aap_instance.host }}"
    #controller_oauthtoken: "{{ selected_aap_instance.oauth_token }}"
    #validate_certs: "{{ controller_validate_certs | default(true) }}"
    #organization: MY Org
    #name: "{{ schedule_job_name }}"
    #rrule: "{{ dynamic_rrule }}"
    #unified_job_template: "{{ cleanup_job_template_lookup.id }}"
    #job_type: run
    #state: present
    #enabled: true
#    extra_data:
#      vms_to_cleanup: "{{ all_vms_for_cleanup }}"
  run_once: true
  delegate_to: localhost
  connection: local

- name: Schedule a one-time snapshot cleanup in AAP for 7 days from now - Var 2
  ansible.builtin.debug:
    var: "{{ dynamic_rrule | type_debug }}"
  run_once: true
  delegate_to: localhost
  connection: local

So essentially, you have multiple tasks and you can see what is in each variable that you are using. It should not be using the schedule module as you just want to display the variables. You can also use other ways to do this, but I think it will be important for you to see how things are evaluating.

I've included some easy examples of how you can see variables and what they become. I'm also in these examples showing how to force variables to a specific type (https://github.com/tmichett/AnsiblePlaybooks/blob/master/Vars/Variables_Demo_Control.yml)

https://github.com/tmichett/AnsiblePlaybooks/tree/master/Vars

 

Travis Michette, RHCA XIII
https://rhtapps.redhat.com/verify?certId=111-134-086
SENIOR TECHNICAL INSTRUCTOR / CERTIFIED INSTRUCTOR AND EXAMINER
Red Hat Certification + Training
0 Kudos
smi-andrew
Flight Engineer
Flight Engineer
  • 111 Views

No worries.

smi-andrew
Flight Engineer
Flight Engineer
  • 54 Views

Hi I just wanted to let you know I got this resolved.....I THINK.  I was trying to ue a variable that had the NEW template ID in it.  After some researching I ended up using the same variable as {{ schedule_job_name }} and it created it.

 

So I should find out in 20ish min if the removal job runs and works.  

I'm not closing this out yet.  But by friday I should be good to go.

THANK YOU for your help!  

0 Kudos
Join the discussion
You must log in to join this conversation.