diff --git a/README.md b/README.md index 4e45667..2e6c63d 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ The list of JC tags you want a host or a group of hosts to be part of - 'tag_two' #### [`jumpcloud_displayName`][jumpcloud-displayName] -Default: `{{ inventory_hostname }}`` +Default: ` {{ inventory_hostname }}`` #### [`jumpcloud_allowPublicKeyAuthentication`][jumpcloud-allowPublicKeyAuthentication] Default: `'true'` diff --git a/meta/main.yml b/meta/main.yml index 2fd8cdf..a273e3d 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -7,10 +7,6 @@ galaxy_info: license: MIT min_ansible_version: 2 platforms: - - name: Centos - versions: - - 6 - - 7 - name: EL versions: - 6 diff --git a/tasks/get_system_key.yml b/tasks/get_system_key.yml index a62b55c..0ff606e 100644 --- a/tasks/get_system_key.yml +++ b/tasks/get_system_key.yml @@ -1,9 +1,11 @@ --- -- command: grep -o -P '(?<=systemKey\":\")[a-zA-Z0-9]*' {{ jumpcloud_agent_config }} +- name: Look for Jumpcloud System Key + command: grep -o -P '(?<=systemKey\":\")[a-zA-Z0-9]*' {{ jumpcloud_agent_config }} register: jumpcloud_system_key_result become: "{{ jumpcloud_use_sudo }}" changed_when: "not jumpcloud_system_key_result.stdout" -- set_fact: +- name: Set Jumpcloud System Key + set_fact: jumpcloud_system_key: "{{ jumpcloud_system_key_result.stdout }}" ... diff --git a/tasks/install.yml b/tasks/install.yml index fa78706..b7050de 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -12,7 +12,7 @@ - name: Saving the position of the `/etc/issue` backup set_fact: - issue_backup_file: "{{ line_infile_result.backup}}" + issue_backup_file: "{{ line_infile_result.backup }}" when: ansible_distribution == "Ubuntu" and "12" in ansible_distribution_version and line_infile_result is defined and (not jumpcloud_is_installed or jumpcloud_force_install) - name: Download JumpCloud Kickstart script @@ -25,9 +25,9 @@ become: "{{ jumpcloud_use_sudo }}" - name: Install JumpCloud Agent - shell: "{{ jumpcloud_kickstart_script }}" + command: "{{ jumpcloud_kickstart_script }}" args: - creates: "{{ jumpcloud_agent_config}}" + creates: "{{ jumpcloud_agent_config }}" become: "{{ jumpcloud_use_sudo }}" - name: Check JumpCloud agent config again @@ -38,7 +38,7 @@ - name: Check again if JumpCloud has been initialised set_fact: - jumpcloud_is_installed: "{{ jumpcloud_agent_config_status.stat.isreg is defined and jumpcloud_agent_config_status.stat.isreg}}" + jumpcloud_is_installed: "{{ jumpcloud_agent_config_status.stat.isreg is defined and jumpcloud_agent_config_status.stat.isreg }}" - name: Reset JumpCloud if `jcagent.conf` has not been created import_tasks: reset_jumpcloud.yml @@ -46,7 +46,7 @@ - name: Restore '/etc/issue' backup if present file: - src: "{{issue_backup_file}}" + src: "{{ issue_backup_file }}" path: /etc/issue state: hard force: yes @@ -54,7 +54,7 @@ - name: Removes '/etc/issue' backup file if present file: - path: "{{issue_backup_file}}" + path: "{{ issue_backup_file }}" state: absent when: issue_backup_file is defined ... diff --git a/tasks/main.yml b/tasks/main.yml index b8b7ea2..57baa3f 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -5,7 +5,8 @@ register: jumpcloud_agent_config_status become: "{{ jumpcloud_use_sudo }}" -- set_fact: +- name: Set whether Jumpcloud is already installed + set_fact: jumpcloud_is_installed: "{{ (jumpcloud_agent_config_status.stat.isreg is defined and jumpcloud_agent_config_status.stat.isreg) }}" - name: Remove registered systems with the same displayName from JumpCloud diff --git a/tasks/remove_registered_systems.yml b/tasks/remove_registered_systems.yml index 2b49697..743bece 100644 --- a/tasks/remove_registered_systems.yml +++ b/tasks/remove_registered_systems.yml @@ -21,12 +21,13 @@ when: jumpcloud_displayName is defined ignore_errors: yes -- set_fact: +- name: Set count of inactive registere systems + set_fact: jc_count_of_inactive_registered_systems: "{{ jc_registered_systems_json_response.json.totalCount }}" - name: Delete the registered systems with the same name from JumpCloud uri: - url: "{{ jumpcloud_api_v1_url }}/systems/{{item._id}}" + url: "{{ jumpcloud_api_v1_url }}/systems/{{ item._id }}" method: DELETE headers: "Content-Type": "application/json" diff --git a/tasks/reset_jumpcloud.yml b/tasks/reset_jumpcloud.yml index ceb4231..e77e3f6 100644 --- a/tasks/reset_jumpcloud.yml +++ b/tasks/reset_jumpcloud.yml @@ -7,19 +7,19 @@ - name: remove JumpCloud CA certificate file: - path: "{{jumpcloud_ca_cert}}" + path: "{{ jumpcloud_ca_cert }}" state: absent become: "{{ jumpcloud_use_sudo }}" - name: remove JumpCloud Client certificate file: - path: "{{jumpcloud_client_cert}}" + path: "{{ jumpcloud_client_cert }}" state: absent become: "{{ jumpcloud_use_sudo }}" - name: remove JumpCloud Client Key file: - path: "{{jumpcloud_client_key}}" + path: "{{ jumpcloud_client_key }}" state: absent become: "{{ jumpcloud_use_sudo }}" @@ -34,7 +34,7 @@ path: "{{ jumpcloud_agent_config }}" state: present timeout: 60 - msg: Timeout to find file "{{ jumpcloud_agent_config}}" + msg: Timeout to find file "{{ jumpcloud_agent_config }}" become: "{{ jumpcloud_use_sudo }}" - name: check JumpCloud agent config again @@ -45,5 +45,5 @@ - name: check again if JumpCloud is installed set_fact: - jumpcloud_is_installed: "{{ jumpcloud_agent_config_status.stat.isreg is defined and jumpcloud_agent_config_status.stat.isreg}}" + jumpcloud_is_installed: "{{ jumpcloud_agent_config_status.stat.isreg is defined and jumpcloud_agent_config_status.stat.isreg }}" ... diff --git a/tasks/update_groups.yml b/tasks/update_groups.yml index 5cbb9bf..b9900f5 100644 --- a/tasks/update_groups.yml +++ b/tasks/update_groups.yml @@ -17,7 +17,7 @@ - name: Create the list of System Groups attributes set_fact: jc_system_groups={{ jc_system_groups|default([]) | union(item.json) }} - with_items: "{{ jc_system_groups_json_response.results}}" + with_items: "{{ jc_system_groups_json_response.results }}" delegate_to: localhost no_log: True diff --git a/tests/playbook.yml b/tests/playbook.yml index 1b7a36d..5925184 100644 --- a/tests/playbook.yml +++ b/tests/playbook.yml @@ -9,7 +9,7 @@ roles: - role: provision-docker provision_docker_network: host - provision_docker_inventory_group: "{{ groups['docker_containers']}}" + provision_docker_inventory_group: "{{ groups['docker_containers'] }}" - hosts: docker_containers gather_facts: false @@ -42,7 +42,7 @@ - name: Update the hostname raw: bash -c "(hostname | grep -x {{ test_hostname }}) || hostname {{ test_hostname }}" register: output - changed_when: output.stdout == "" + changed_when: output.stdout | length == 0 roles: - { role: ansible-jumpcloud } diff --git a/tests/playbook_delete_containers.yml b/tests/playbook_delete_containers.yml index df358d6..d0e5376 100644 --- a/tests/playbook_delete_containers.yml +++ b/tests/playbook_delete_containers.yml @@ -7,7 +7,7 @@ jumpcloud_api_key: "{{ lookup('env','JUMPCLOUD_API_KEY') }}" jumpcloud_use_sudo: true jumpcloud_displayName: "ansible-jc-role-{{ test_hostname }}" - + tasks: - include_role: name: ansible-jumpcloud diff --git a/tests/tasks/check_docker.yml b/tests/tasks/check_docker.yml index 75e6fd5..6f195e9 100644 --- a/tests/tasks/check_docker.yml +++ b/tests/tasks/check_docker.yml @@ -1,11 +1,12 @@ --- - name: Get `docker` status - local_action: shell type docker + command: type docker register: docker_status ignore_errors: true run_once: true changed_when: false + delegate_to: localhost - name: Check if `docker` is installed set_fact: diff --git a/tests/tasks/fix_apt_show_versions.yml b/tests/tasks/fix_apt_show_versions.yml index 2385a71..9d07755 100644 --- a/tests/tasks/fix_apt_show_versions.yml +++ b/tests/tasks/fix_apt_show_versions.yml @@ -2,22 +2,15 @@ - name: Remove "/etc/apt/apt.conf.d/docker-gzip-indexes" raw: bash -c "rm /etc/apt/apt.conf.d/docker-gzip-indexes" register: output - changed_when: output.stdout != "" + changed_when: output.stdout | length > 0 when: '"debian" in inventory_hostname or "ubuntu" in inventory_hostname' become: "{{ jumpcloud_use_sudo }}" ignore_errors: true - # - name: Purge "apt-show-versions" - # raw: bash -c "apt-get -y purge apt-show-versions" - # register: output - # changed_when: false - # when: '"debian" in inventory_hostname or "ubuntu" in inventory_hostname' - # become: "{{ jumpcloud_use_sudo }}" - - name: Remove "/var/lib/apt/lists/*lz4" raw: bash -c "rm /var/lib/apt/lists/*lz4" register: output - changed_when: output.stdout != "" + changed_when: output.stdout | length > 0 when: '"debian" in inventory_hostname or "ubuntu" in inventory_hostname' become: "{{ jumpcloud_use_sudo }}" ignore_errors: true diff --git a/tests/tasks/install_python.yml b/tests/tasks/install_python.yml index 4b25549..4f6c38d 100644 --- a/tests/tasks/install_python.yml +++ b/tests/tasks/install_python.yml @@ -2,14 +2,14 @@ - name: Install Python on CentoOS or RHEL systems if not present raw: bash -c "test -e /usr/bin/python || (yum -qy update && yum install -qy python python-pip python3 python3-pip)" register: output - changed_when: output.stdout != "" + changed_when: output.stdout | length > 0 when: '"centos" in inventory_hostname or "rehel" in inventory_hostname' become: "{{ jumpcloud_use_sudo }}" - name: Install Python on Ubuntu or Debian systems if not present raw: bash -c "test -e /usr/bin/python || (apt -qqy update && apt install -qqy python python-pip python3 python3-pip)" register: output - changed_when: output.stdout != "" + changed_when: output.stdout | length > 0 when: '"ubuntu" in inventory_hostname or "debian" in inventory_hostname' become: "{{ jumpcloud_use_sudo }}" ... diff --git a/tests/tasks/install_yum_patch.yml b/tests/tasks/install_yum_patch.yml index 3727f96..43e92c8 100644 --- a/tests/tasks/install_yum_patch.yml +++ b/tests/tasks/install_yum_patch.yml @@ -2,7 +2,7 @@ - name: Install YUM patch on CentOS images raw: bash -c "test -e /etc/yum/pluginconf.d/ovl.conf || yum install -qy yum-plugin-ovl" register: output - changed_when: output.stdout != "" + changed_when: output.stdout | length > 0 when: '"centos" in inventory_hostname' become: "{{ jumpcloud_use_sudo }}" ignore_errors: true diff --git a/tests/tasks/test_tasks.yml b/tests/tasks/test_tasks.yml index 36faa48..51c549f 100644 --- a/tests/tasks/test_tasks.yml +++ b/tests/tasks/test_tasks.yml @@ -8,14 +8,14 @@ assert: that: - "jc_system_is_registered" - msg: "The host {{jumpcloud_displayName}} has not been registered to Jumpcloud" + msg: "The host {{ jumpcloud_displayName }} has not been registered to Jumpcloud" delegate_to: localhost - name: Check that the registered host name correspond to the System hostname assert: that: - "jumpcloud_displayName in jc_system_attributes_json_response.json.displayName" - msg: "The host should be named {{jumpcloud_displayName}} but is present in JumpCloud as {{jc_system_attributes_json_response.json.displayName}}" + msg: "The host should be named {{ jumpcloud_displayName }} but is present in JumpCloud as {{ jc_system_attributes_json_response.json.displayName }}" when: jc_system_is_registered delegate_to: localhost @@ -41,8 +41,9 @@ when: jumpcloud_system_key is defined and jumpcloud_system_groups is defined ignore_errors: yes -- set_fact: jc_system_memberof={{ jc_system_memberof|default([]) | union([item.id]) }} - with_items: "{{ jc_system_memberof_json_response.json}}" +- name: Set the system membership to groups + set_fact: jc_system_memberof={{ jc_system_memberof|default([]) | union([item.id]) }} + with_items: "{{ jc_system_memberof_json_response.json }}" delegate_to: localhost when: jumpcloud_system_groups is defined no_log: true @@ -51,8 +52,8 @@ assert: that: - "item.id in jc_system_memberof" - msg: "The host seems not to be member of the required System Groups {{jumpcloud_system_groups}}" - with_items: "{{jc_system_groups}}" + msg: "The host seems not to be member of the required System Groups {{ jumpcloud_system_groups }}" + with_items: "{{ jc_system_groups }}" delegate_to: localhost when: jumpcloud_system_groups is defined ...