Handle 'state' (present,attached,absent,detached)

This commit is contained in:
Sebastien Thebert committed 2022-10-30 01:29:02 +02:00
1 parent 7cc01844f1
commit 6a09818893
5 files changed
+52 -12

No files matched your search

+16 -4
View File
@@ -1,20 +1,32 @@
---
- name: 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'
# include_tasks: requirements.yml
- name: Include tasks 'requirements.yml'
include_tasks: requirements.yml
when: state == 'present' or state == 'attached'
- name: Include tasks 'configure.yml'
include_tasks: configure.yml
when: state == 'present' or state == 'attached'
- name: Include tasks 'register.yml'
include_tasks: register.yml
when: state == 'present' or state == 'attached'
- name: 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'
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'
+2
View File
@@ -3,8 +3,10 @@
ansible.builtin.command: "pro attach {{ ubuntu_pro_token }}"
become: yes
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])
- name: Print 'pro attach' command output
ansible.builtin.debug:
var: reg_pro_attach
when: debug
+8 -8
View File
@@ -1,13 +1,13 @@
---
- name: Launch 'apt update'
ansible.builtin.apt:
update_cache: yes
become: yes
# - name: Launch 'apt update'
# ansible.builtin.apt:
# update_cache: yes
# become: yes
- name: Launch 'apt upgrade'
ansible.builtin.apt:
upgrade: yes
become: yes
# - name: Launch 'apt upgrade'
# ansible.builtin.apt:
# upgrade: yes
# become: yes
- name: Install 'ubuntu-advantage-tools' package
ansible.builtin.apt:
+6
View File
@@ -0,0 +1,6 @@
---
- name: Uninstall 'ubuntu-advantage-tools' package
ansible.builtin.apt:
name: ubuntu-advantage-tools
state: absent
become: yes
+20
View File
@@ -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)