Handle 'state' (present,attached,absent,detached)
This commit is contained in:
1 parent
7cc01844f1
commit
6a09818893
5 files changed
+52
-12
No files matched your search
+16
-4
@@ -1,20 +1,32 @@
|
|||||||
---
|
---
|
||||||
- name: Include tasks 'validate_ubuntu_lts_version.yml'
|
- name: Include tasks 'validate_ubuntu_lts_version.yml'
|
||||||
include_tasks: validate_ubuntu_lts_version.yml
|
include_tasks: validate_ubuntu_lts_version.yml
|
||||||
|
when: state == 'present' or state == 'attached'
|
||||||
|
|
||||||
# - name: Include tasks 'requirements.yml'
|
- name: Include tasks 'requirements.yml'
|
||||||
# include_tasks: requirements.yml
|
include_tasks: requirements.yml
|
||||||
|
when: state == 'present' or state == 'attached'
|
||||||
|
|
||||||
- name: Include tasks 'configure.yml'
|
- name: Include tasks 'configure.yml'
|
||||||
include_tasks: configure.yml
|
include_tasks: configure.yml
|
||||||
|
when: state == 'present' or state == 'attached'
|
||||||
|
|
||||||
- name: Include tasks 'register.yml'
|
- name: Include tasks 'register.yml'
|
||||||
include_tasks: register.yml
|
include_tasks: register.yml
|
||||||
|
when: state == 'present' or state == 'attached'
|
||||||
|
|
||||||
- name: Include tasks 'enable_services.yml'
|
- name: Include tasks 'enable_services.yml'
|
||||||
include_tasks: enable_services.yml
|
include_tasks: enable_services.yml
|
||||||
when: enabled_services is defined
|
when: enabled_services is defined and (state == 'present' or state == 'attached')
|
||||||
|
|
||||||
- name: Include tasks 'disable_services.yml'
|
- name: Include tasks 'disable_services.yml'
|
||||||
include_tasks: disable_services.yml
|
include_tasks: disable_services.yml
|
||||||
when: disabled_services is defined
|
when: disabled_services is defined and (state == 'present' or state == 'attached')
|
||||||
|
|
||||||
|
- name: Include tasks 'unregister.yml'
|
||||||
|
include_tasks: unregister.yml
|
||||||
|
when: state == 'absent' or state == 'detached'
|
||||||
|
|
||||||
|
- name: Include tasks 'uninstall.yml'
|
||||||
|
include_tasks: uninstall.yml
|
||||||
|
when: state == 'absent'
|
||||||
@@ -3,8 +3,10 @@
|
|||||||
ansible.builtin.command: "pro attach {{ ubuntu_pro_token }}"
|
ansible.builtin.command: "pro attach {{ ubuntu_pro_token }}"
|
||||||
become: yes
|
become: yes
|
||||||
register: reg_pro_attach
|
register: reg_pro_attach
|
||||||
|
changed_when: reg_pro_attach.rc == 0
|
||||||
failed_when: (reg_pro_attach.rc != 0) and ('This machine is already attached to' not in reg_pro_attach.stderr_lines[0])
|
failed_when: (reg_pro_attach.rc != 0) and ('This machine is already attached to' not in reg_pro_attach.stderr_lines[0])
|
||||||
|
|
||||||
- name: Print 'pro attach' command output
|
- name: Print 'pro attach' command output
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
var: reg_pro_attach
|
var: reg_pro_attach
|
||||||
|
when: debug
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
---
|
---
|
||||||
- name: Launch 'apt update'
|
# - name: Launch 'apt update'
|
||||||
ansible.builtin.apt:
|
# ansible.builtin.apt:
|
||||||
update_cache: yes
|
# update_cache: yes
|
||||||
become: yes
|
# become: yes
|
||||||
|
|
||||||
- name: Launch 'apt upgrade'
|
# - name: Launch 'apt upgrade'
|
||||||
ansible.builtin.apt:
|
# ansible.builtin.apt:
|
||||||
upgrade: yes
|
# upgrade: yes
|
||||||
become: yes
|
# become: yes
|
||||||
|
|
||||||
- name: Install 'ubuntu-advantage-tools' package
|
- name: Install 'ubuntu-advantage-tools' package
|
||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
- name: Uninstall 'ubuntu-advantage-tools' package
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name: ubuntu-advantage-tools
|
||||||
|
state: absent
|
||||||
|
become: yes
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
- ansible.builtin.shell: "command pro"
|
||||||
|
register: reg_command_pro
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- set_fact:
|
||||||
|
pro_command_exists: "{{ (reg_command_pro.rc == 127) | ternary(false, true) }}"
|
||||||
|
|
||||||
|
- name: Unregister this host on Ubuntu Pro (pro detach)
|
||||||
|
ansible.builtin.command: "pro detach --assume-yes"
|
||||||
|
become: yes
|
||||||
|
register: reg_pro_detach
|
||||||
|
changed_when: reg_pro_detach.rc == 0
|
||||||
|
failed_when: (reg_pro_detach.rc != 0) and ('This machine is not attached to an Ubuntu Pro subscription.' not in reg_pro_detach.stderr_lines[0])
|
||||||
|
when: pro_command_exists
|
||||||
|
|
||||||
|
- name: Print 'pro detach' command output
|
||||||
|
ansible.builtin.debug:
|
||||||
|
var: reg_pro_detach
|
||||||
|
when: (debug and pro_command_exists)
|
||||||
Reference in new issue
Block a user