diff --git a/tasks/disable_services.yml b/tasks/disable_services.yml new file mode 100644 index 0000000..ac21b6e --- /dev/null +++ b/tasks/disable_services.yml @@ -0,0 +1,11 @@ +--- +- name: Disable services + ansible.builtin.command: "pro disable {{ item }}" + become: yes + register: reg_pro_disable + when: item in ubuntu_pro_services + loop: "{{ disabled_services }}" + changed_when: reg_pro_disable.rc == 0 + failed_when: + - reg_pro_disable.rc != 0 + - ('is not currently enabled' not in reg_pro_disable.stdout_lines[0]) diff --git a/tasks/enable_services.yml b/tasks/enable_services.yml new file mode 100644 index 0000000..20fb604 --- /dev/null +++ b/tasks/enable_services.yml @@ -0,0 +1,11 @@ +--- +- name: Enable services + ansible.builtin.command: "pro enable {{ item }}" + become: yes + register: reg_pro_enable + when: item in ubuntu_pro_services + loop: "{{ enabled_services }}" + changed_when: reg_pro_enable.rc == 0 + failed_when: + - reg_pro_enable.rc != 0 + - ('is already enabled' not in reg_pro_enable.stdout_lines[1] and 'is not available for' not in reg_pro_enable.stdout_lines[1]) diff --git a/tasks/main.yml b/tasks/main.yml index 10f0fb6..2d96dec 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,29 +1,20 @@ --- -- include_tasks: validate_ubuntu_lts_version.yml +- name: Include tasks 'validate_ubuntu_lts_version.yml' + include_tasks: validate_ubuntu_lts_version.yml -- name: Launch 'apt update' - ansible.builtin.apt: - update_cache: yes - become: yes +# - name: Include tasks 'requirements.yml' +# include_tasks: requirements.yml -- name: Launch 'apt upgrade' - ansible.builtin.apt: - upgrade: yes - become: yes +- name: Include tasks 'configure.yml' + include_tasks: configure.yml -- name: Install 'ubuntu-advantage-tools' package - ansible.builtin.apt: - name: ubuntu-advantage-tools - state: latest - become: yes +- name: Include tasks 'register.yml' + include_tasks: register.yml -- include_tasks: configure.yml +- name: Include tasks 'enable_services.yml' + include_tasks: enable_services.yml + when: enabled_services is defined -- name: Register this host on Ubuntu Pro (pro attach ) - ansible.builtin.command: "pro attach {{ ubuntu_pro_token }}" - become: yes - register: reg_pro_attach - -- name: Print 'pro attach' command output - ansible.builtin.debug: - var: reg_pro_attach +- name: Include tasks 'disable_services.yml' + include_tasks: disable_services.yml + when: disabled_services is defined diff --git a/tasks/register.yml b/tasks/register.yml new file mode 100644 index 0000000..6f71165 --- /dev/null +++ b/tasks/register.yml @@ -0,0 +1,10 @@ +--- +- name: Register this host on Ubuntu Pro (pro attach ) + ansible.builtin.command: "pro attach {{ ubuntu_pro_token }}" + become: yes + register: reg_pro_attach + 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 diff --git a/tasks/requirements.yml b/tasks/requirements.yml new file mode 100644 index 0000000..bb5b2ed --- /dev/null +++ b/tasks/requirements.yml @@ -0,0 +1,16 @@ +--- +- name: Launch 'apt update' + ansible.builtin.apt: + update_cache: yes + become: yes + +- name: Launch 'apt upgrade' + ansible.builtin.apt: + upgrade: yes + become: yes + +- name: Install 'ubuntu-advantage-tools' package + ansible.builtin.apt: + name: ubuntu-advantage-tools + state: latest + become: yes diff --git a/vars/main.yml b/vars/main.yml index d7768dd..2288217 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -18,10 +18,10 @@ ubuntu_pro_lts_releases: # update_status_timer: 43200 # metering_timer: 14400 -# ubuntu_pro_services: -# - 'cc-eal' # Common Criteria EAL2 -# - 'esm-infra' # Expanded Security Maintenance for Infrastructure -# - 'fips' -# - 'fips-updates' -# - 'livepatch' # Canonical Kernel Livepatch -# - 'usg' # Ubuntu Security Guide +ubuntu_pro_services: + - 'cc-eal' # Common Criteria EAL2 + - 'esm-infra' # Expanded Security Maintenance for Infrastructure + - 'fips' + - 'fips-updates' + - 'livepatch' # Canonical Kernel Livepatch + - 'usg' # Ubuntu Security Guide