Skip to content

Commit

Permalink
ansible-lint adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomc committed May 8, 2019
1 parent 2bef3d2 commit ad562ba
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 44 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'`
Expand Down
4 changes: 0 additions & 4 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ galaxy_info:
license: MIT
min_ansible_version: 2
platforms:
- name: Centos
versions:
- 6
- 7
- name: EL
versions:
- 6
Expand Down
6 changes: 4 additions & 2 deletions tasks/get_system_key.yml
Original file line number Diff line number Diff line change
@@ -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 }}"
...
12 changes: 6 additions & 6 deletions tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -38,23 +38,23 @@

- 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
when: not jumpcloud_is_installed

- name: Restore '/etc/issue' backup if present
file:
src: "{{issue_backup_file}}"
src: "{{ issue_backup_file }}"
path: /etc/issue
state: hard
force: yes
when: issue_backup_file is defined

- 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
...
3 changes: 2 additions & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions tasks/remove_registered_systems.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions tasks/reset_jumpcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"

Expand All @@ -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
Expand All @@ -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 }}"
...
2 changes: 1 addition & 1 deletion tasks/update_groups.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions tests/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion tests/playbook_delete_containers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/tasks/check_docker.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
11 changes: 2 additions & 9 deletions tests/tasks/fix_apt_show_versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/tasks/install_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
...
2 changes: 1 addition & 1 deletion tests/tasks/install_yum_patch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions tests/tasks/test_tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
...

0 comments on commit ad562ba

Please sign in to comment.