xci: playbooks: Fixes various ansible-lint warnings 73/54473/4
authorMarkos Chandras <mchandras@suse.de>
Mon, 26 Mar 2018 09:23:13 +0000 (10:23 +0100)
committerMarkos Chandras <mchandras@suse.de>
Mon, 26 Mar 2018 19:47:17 +0000 (20:47 +0100)
In preparation for adding support for the 'ansible-lint' tool we fix
various problems in our playbooks to make the tool happy before we make
it mandatory.

Some of the problems that are fixed here are

- [ANSIBLE0011] All tasks should be named
- [ANSIBLE0012] Commands should not change things if nothing needs doing
- [ANSIBLE0013] Use shell only when shell functionality is required
- [ANSIBLE0010] Package installs should not use latest

installer-type:osa
deploy-scenario:os-nosdn-nofeature
Change-Id: I66c759d3932a414b81b2846393d2d98ce80c0b6d
Signed-off-by: Markos Chandras <mchandras@suse.de>
xci/installer/kubespray/playbooks/configure-opnfvhost.yml
xci/installer/osa/playbooks/configure-opnfvhost.yml
xci/playbooks/configure-localhost.yml
xci/playbooks/get-opnfv-scenario-requirements.yml
xci/playbooks/roles/bootstrap-host/tasks/network.yml
xci/playbooks/roles/bootstrap-host/tasks/time.yml
xci/playbooks/roles/configure-nfs/tasks/main.yml
xci/playbooks/roles/prepare-functest/tasks/main.yml

index 8166b0e..eed814b 100644 (file)
@@ -31,7 +31,7 @@
         delete: yes
 
     - name: generate SSH keys
-      shell: ssh-keygen -b 2048 -t rsa -f /root/.ssh/id_rsa -q -N ""
+      command: ssh-keygen -b 2048 -t rsa -f /root/.ssh/id_rsa -q -N ""
       args:
         creates: /root/.ssh/id_rsa
     - name: add id_rsa.pub to authorized_keys
         path: "{{ remote_xci_path }}/.cache/repos/kubespray/opnfv_inventory"
         state: absent
     - name: copy kubespray inventory directory
-      shell: "cp -rf {{ remote_xci_flavor_files }}/inventory \
+      command: "cp -rf {{ remote_xci_flavor_files }}/inventory \
                    {{ remote_xci_path }}/.cache/repos/kubespray/opnfv_inventory"
+      args:
+        creates: "{{ remote_xci_path }}/.cache/repos/kubespray/opnfv_inventory"
     - name: make sure kubespray/opnfv_inventory/group_vars/ exist
       file:
         path: "{{ remote_xci_path }}/.cache/repos/kubespray/opnfv_inventory/group_vars"
         state: directory
     - name: copy k8s_cluster.yml
-      shell: "cp -rf {{ remote_xci_path }}/xci/installer/kubespray/files/k8s-cluster.yml \
+      command: "cp -rf {{ remote_xci_path }}/xci/installer/kubespray/files/k8s-cluster.yml \
                      {{ remote_xci_path }}/.cache/repos/kubespray/opnfv_inventory/group_vars"
+      args:
+        creates: "{{ remote_xci_path }}/.cache/repos/kubespray/opnfv_inventory/group_vars"
     - name: Install required packages
       package:
         name: "{{ kube_require_packages[ansible_pkg_mgr] }}"
@@ -82,3 +86,5 @@
   tasks:
     - name: Append public keys to authorized_keys
       shell: "/bin/cat {{ ansible_env.HOME }}/.ssh/id_rsa.pub >> {{ xci_path }}/xci/files/authorized_keys"
+      args:
+        creates: "{{ xci_path }}/xci/files/authorized_keys"
index 2485f47..001fcee 100644 (file)
 
   tasks:
     - name: generate SSH keys
-      shell: ssh-keygen -b 2048 -t rsa -f /root/.ssh/id_rsa -q -N ""
+      command: ssh-keygen -b 2048 -t rsa -f /root/.ssh/id_rsa -q -N ""
       args:
         creates: "{{ ansible_env.HOME }}/.ssh/id_rsa"
+      changed_when: True
     - name: fetch public key
       fetch:
         src: "{{ ansible_env.HOME }}/.ssh/id_rsa.pub"
         recursive: yes
         delete: yes
     - name: copy flavor inventory
-      shell: "/bin/cp -rf {{ remote_xci_flavor_files }}/inventory {{ remote_xci_playbooks }}"
+      command: "/bin/cp -rf {{ remote_xci_flavor_files }}/inventory {{ remote_xci_playbooks }}"
+      args:
+        creates: "{{ remote_xci_playbooks }}/inventory"
     - name: copy openstack_deploy
-      shell: "/bin/cp -rf {{openstack_osa_path}}/etc/openstack_deploy {{openstack_osa_etc_path}}"
+      command: "/bin/cp -rf {{openstack_osa_path}}/etc/openstack_deploy {{openstack_osa_etc_path}}"
+      args:
+        creates: "{{ openstack_osa_etc_path }}"
     - name: copy openstack_user_config.yml
-      shell: "/bin/cp -rf {{ remote_xci_flavor_files }}/openstack_user_config.yml {{openstack_osa_etc_path}}"
+      command: "/bin/cp -rf {{ remote_xci_flavor_files }}/openstack_user_config.yml {{openstack_osa_etc_path}}"
+      args:
+        creates: "{{ openstack_osa_etc_path }}/openstack_user_config.yml"
       failed_when: false
     - name: copy all user override files
-      shell: "/bin/cp -rf {{ remote_xci_flavor_files }}/user_variables.yml {{openstack_osa_etc_path}}"
+      command: "/bin/cp -rf {{ remote_xci_flavor_files }}/user_variables.yml {{openstack_osa_etc_path}}"
+      args:
+        creates: "{{ openstack_osa_etc_path }}/user_variables.yml }}"
       failed_when: false
     - name: copy cinder.yml
-      shell: "/bin/cp -rf {{ remote_xci_path }}/xci/installer/osa/files/cinder.yml {{openstack_osa_etc_path}}/env.d"
+      command: "/bin/cp -rf {{ remote_xci_path }}/xci/installer/osa/files/cinder.yml {{openstack_osa_etc_path}}/env.d"
+      args:
+        creates: "{{ openstack_osa_etc_path }}/env.d/cinder.yml"
     - name: Configure OpenStack-Ansible components
       lineinfile:
         path: "{{ openstack_osa_etc_path }}/user_variables.yml"
         - { component: "core_openstack", value: "{{ core_openstack_install | bool }}" }
     - block:
         - name: copy ceph.yml
-          shell: "/bin/cp -rf {{ remote_xci_flavor_files }}/ceph.yml {{openstack_osa_etc_path}}/conf.d/"
+          command: "/bin/cp -rf {{ remote_xci_flavor_files }}/ceph.yml {{openstack_osa_etc_path}}/conf.d/"
+          args:
+            creates: "{{ openstack_osa_etc_path }}/conf.d/ceph.yml"
         - name: copy user_ceph.yml
-          shell: "/bin/cp -rf {{ remote_xci_flavor_files }}/user_ceph.yml {{openstack_osa_etc_path}}/user_ceph.yml"
+          command: "/bin/cp -rf {{ remote_xci_flavor_files }}/user_ceph.yml {{openstack_osa_etc_path}}/user_ceph.yml"
+          args:
+            creates: "{{ openstack_osa_etc_path }}/user_ceph.yml"
         - name: copy user_variables_ceph.yml
-          shell: "/bin/cp -rf {{ remote_xci_flavor_files }}/user_variables_ceph.yml {{openstack_osa_etc_path}}/user_variables_ceph.yml"
+          command: "/bin/cp -rf {{ remote_xci_flavor_files }}/user_variables_ceph.yml {{openstack_osa_etc_path}}/user_variables_ceph.yml"
+          args:
+            creates: "{{ openstack_osa_etc_path }}/user_variables_ceph.yml"
       when: xci_ceph_enabled == "true"
     - block:
         - name: copy user_variables_proxy.yml
-          shell: "/bin/cp -rf {{ remote_xci_path }}/xci/installer/osa/files/user_variables_proxy.yml {{openstack_osa_etc_path}}/user_variables_proxy.yml"
+          command: "/bin/cp -rf {{ remote_xci_path }}/xci/installer/osa/files/user_variables_proxy.yml {{openstack_osa_etc_path}}/user_variables_proxy.yml"
+          args:
+            creates: "{{ openstack_osa_etc_path }}/user_variables_proxy.yml"
         - name: "Configure http_proxy_env_url"
           lineinfile:
             path: "{{openstack_osa_etc_path}}/user_variables_proxy.yml"
       when:
         - lookup('env','http_proxy') != "randomfoobarstring"
     - name: copy OPNFV OpenStack playbook
-      shell: "/bin/cp -rf {{ remote_xci_path }}/xci/installer/osa/files/setup-openstack.yml {{openstack_osa_path}}/playbooks"
+      command: "/bin/cp -rf {{ remote_xci_path }}/xci/installer/osa/files/setup-openstack.yml {{openstack_osa_path}}/playbooks"
+      args:
+        creates: "{{ openstack_osa_path }}/playbooks/setup-openstack.yml"
     - name: copy pinned versions of OSA Roles and global requirements
-      shell: "/bin/cp -rf {{ remote_xci_path }}/xci/installer/osa/files/{{ item }} {{openstack_osa_path}}/{{ item }}"
+      command: "/bin/cp -rf {{ remote_xci_path }}/xci/installer/osa/files/{{ item }} {{openstack_osa_path}}/{{ item }}"
+      args:
+        creates: "{{ openstack_osa_path }}/{{ item }}"
       with_items:
         - "ansible-role-requirements.yml"
         - "global-requirement-pins.txt"
       when:
         - openstack_osa_version != "master"
     - name: copy pinned versions of OpenStack services
-      shell: "/bin/cp -rf {{ remote_xci_path }}/xci/installer/osa/files/openstack_services.yml {{openstack_osa_path}}/playbooks/defaults/repo_packages/openstack_services.yml"
+      command: "/bin/cp -rf {{ remote_xci_path }}/xci/installer/osa/files/openstack_services.yml {{openstack_osa_path}}/playbooks/defaults/repo_packages/openstack_services.yml"
+      args:
+        creates: "{{ openstack_osa_path }}/playbooks/defaults/repo_packages/openstack_services.yml"
       when:
         - openstack_osa_version != "master"
     - include: "{{ xci_path }}/xci/playbooks/bootstrap-scenarios.yml"
     - name: bootstrap ansible on opnfv host
       command: "/bin/bash ./scripts/bootstrap-ansible.sh"
+      changed_when: True
       args:
         chdir: "{{openstack_osa_path}}"
     - name: install opnfv pip required packages
         extra_args: '-c https://raw.githubusercontent.com/openstack/requirements/{{ requirements_git_install_branch }}/upper-constraints.txt'
         executable: '/opt/ansible-runtime/bin/pip'
     - name: Determine ARA callback location
-      shell: "/opt/ansible-runtime/bin/python -c 'import os,ara; print(os.path.dirname(ara.__file__))'"
-      args:
-        executable: /bin/bash
+      command: "/opt/ansible-runtime/bin/python -c 'import os,ara; print(os.path.dirname(ara.__file__))'"
+      changed_when: False
       register: _ara_install_dir
     - name: Create local Ansible plugins directory
       file:
       command: "python pw-token-gen.py --file {{openstack_osa_etc_path}}/user_secrets.yml"
       args:
         chdir: "{{openstack_osa_path}}/scripts"
+      changed_when: True
     - name: check if certificate directory /etc/ssl/certs exists already
       stat: path=/etc/ssl/certs
       register: check_etc_ssl_certs
   tasks:
     - name: Append public keys to authorized_keys
       shell: "/bin/cat {{ ansible_env.HOME }}/.ssh/id_rsa.pub >> {{ xci_path }}/xci/files/authorized_keys"
+      changed_when: True
 
 - hosts: opnfv
   remote_user: root
index c8a9840..f64400e 100644 (file)
       shell: env > "{{ xci_path }}/.cache/xci.env"
       args:
         executable: /bin/bash
+        creates: "{{ xci_path }}/.cache/xci.env"
index 3c29138..6572e27 100644 (file)
 
     - name: Determine if the selected {{ deploy_scenario }} scenario can be deployed
       block:
-        - set_fact:
+        - name: Set scenario installer fact
+          set_fact:
             deploy_scenario_installer: "{{ item }}"
           with_items: "{{ deploy_scenario.installers }}"
           loop_control:
             label: "{{ item.installer }}"
           when: item.installer == installer_type
-        - set_fact:
+        - name: Set scenario flavor fact
+          set_fact:
             deploy_scenario_flavor: "{{ (xci_flavor in deploy_scenario_installer.flavors) | bool }}"
           when:
             - deploy_scenario_installer is defined
             - deploy_scenario_installer
-        - set_fact:
+        - name: Set scenario distro flavor fact
+          set_fact:
             deploy_scenario_distro: "{{ (xci_distro in deploy_scenario_installer.distros) | bool }}"
           when:
             - deploy_scenario_flavor is defined
index 01edf45..ea9060e 100644 (file)
         name: 8021q
         state: present
     - name: ensure interfaces.d folder is empty
-      shell: "/bin/rm -rf /etc/network/interfaces.d/*"
+      file:
+        state: "{{ item }}"
+        path: "/etc/network/interfaces.d"
+      with_items:
+        - absent
+        - directory
     - name: ensure interfaces file is updated
       template:
         src: "{{ ansible_os_family | lower }}/{{ ansible_hostname }}.interface.j2"
       poll: 0
   when: ansible_os_family | lower == "redhat"
 
-- local_action:
+- name: Wait for host to come back to life
+  local_action:
     module: wait_for
     host: "{{ ansible_host }}"
     delay: 15
index 4b3bf95..9eca769 100644 (file)
 - name: install chrony
   package:
     name: "chrony"
-    state: latest
+    state: present
 - name: restart chrony
   service:
     name: "{{ (ansible_pkg_mgr == 'apt') | ternary('chrony', 'chronyd') }}"
     state: restarted
 - name: synchronize time
   shell: "chronyc -a 'burst 4/4' && chronyc -a makestep"
+  args:
+    executable: /bin/bash
+  changed_when: True
   register: chrony_got_time
   until: chrony_got_time.rc == 0
   retries: 5
index 25e8149..3b349ad 100644 (file)
@@ -47,7 +47,7 @@
 - name: Install the NFS server package
   package:
     name: "{{ nfs_server_package }}"
-    state: latest
+    state: present
 
 - name: restart NFS service
   service:
index 2797ce4..ad578bf 100644 (file)
   shell: "ip a | grep {{ gateway_ip }}"
   register: gateway_ip_result
   ignore_errors: True
+  changed_when: False
 
 - name: add public network gateway
   command: "ip addr add {{ gateway_ip_mask }} brd {{ broadcast_ip }} dev {{ gateway_interface }}"
+  changed_when: False
   when: gateway_ip_result|failed
 
 - name: prepare environment file for functest