From e436145c4444e5988337ac277fdec5043613d5b3 Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen@paragon-es.de>
Date: Fri, 14 Jun 2019 13:06:44 +0200
Subject: [PATCH] ansible-playbooks/general#85 Make sure cli arguments have an
 explicit order in scripts

---
 lib/script.py                  | 13 +++++++------
 scripts/apache-config.yml      |  4 ++--
 scripts/apt-pin.yml            |  6 +++---
 scripts/bigfiles.yml           |  4 ++--
 scripts/custom.yml             |  2 +-
 scripts/drupal-config.yml      |  6 +++---
 scripts/drupal-deploy.yml      |  4 ++--
 scripts/drupal-dump-db.yml     |  6 +++---
 scripts/drupal-launch.yml      |  4 ++--
 scripts/firewall-unprotect.yml |  2 +-
 scripts/inithost.yml           | 14 +++++++-------
 scripts/initpi.yml             |  8 ++++----
 scripts/jailkit-update.yml     |  2 +-
 scripts/jailkit-user.yml       |  2 +-
 scripts/lists.yml              |  2 +-
 scripts/localhost.yml          |  4 ++--
 scripts/matomo.yml             |  4 ++--
 scripts/netdata.yml            |  2 +-
 scripts/nextcloud-install.yml  |  2 +-
 scripts/nextcloud-plugins.yml  |  2 +-
 scripts/nextcloud.yml          |  2 +-
 scripts/playbook.yml           |  4 ++--
 scripts/removehost.yml         |  4 ++--
 scripts/role.yml               |  2 +-
 scripts/sanity.yml             |  6 +++---
 scripts/setup-local.yml        |  6 +++---
 scripts/userlock.yml           |  2 +-
 scripts/userpwd.yml            |  4 ++--
 scripts/userunlock.yml         |  2 +-
 29 files changed, 63 insertions(+), 62 deletions(-)

diff --git a/lib/script.py b/lib/script.py
index 45db899c..815c2fe0 100644
--- a/lib/script.py
+++ b/lib/script.py
@@ -35,13 +35,14 @@ class Script:
             prefix = '--' if parserType == 'options' else ''
             if parserType in script_def:
                 for item in script_def[parserType]:
-                    print('%s / %s' % (parserType, item))
-                    for kw in script_def[parserType][item]:
-                        if isinstance(script_def[parserType][item][kw], dict) and 'exec' in script_def[parserType][item][kw]:
+                    name = item['name']
+                    item.pop('name')
+                    for kw in item:
+                        if isinstance(item[kw], dict) and 'exec' in item[kw]:
                             result = None
-                            exec(script_def[parserType][item][kw]['exec'])
-                            script_def[parserType][item][kw] = result
-                    parser.add_argument(prefix + item, **script_def[parserType][item])
+                            exec(item[kw]['exec'])
+                            item[kw] = result
+                    parser.add_argument(prefix + name, **item)
 
 
     def ignoresInventory(self):
diff --git a/scripts/apache-config.yml b/scripts/apache-config.yml
index 7860361e..ff76ad1a 100644
--- a/scripts/apache-config.yml
+++ b/scripts/apache-config.yml
@@ -3,10 +3,10 @@
 description: Quickly configure Apache
 cli:
   options:
-    application:
+    - name: application
       default: apache
       help: The application to configure Apache for, e.g. apache, drupal, matomo, nextcloud, kibana
-    site:
+    - name: site
       default: no
       help: The id of a site (only useful with certain applications like Drupal or Matomo)
 arguments:
diff --git a/scripts/apt-pin.yml b/scripts/apt-pin.yml
index 286feb64..299b0142 100644
--- a/scripts/apt-pin.yml
+++ b/scripts/apt-pin.yml
@@ -3,16 +3,16 @@
 description: Pin, unpin or show status of packages
 cli:
   arguments:
-    mode:
+    - name: mode
       choices:
         - status
         - pin
         - unpin
       help: Mode for the pinning
-    package:
+    - name: package
       help: Name of the package
   options:
-    version:
+    - name: version
       default: '*'
       help: Version for which you want to pin
 arguments:
diff --git a/scripts/bigfiles.yml b/scripts/bigfiles.yml
index aba7cd8d..1a25ba78 100644
--- a/scripts/bigfiles.yml
+++ b/scripts/bigfiles.yml
@@ -3,10 +3,10 @@
 description: Find big files / directories
 cli:
   options:
-    depth:
+    - name: depth
       default: 5
       help: How many directories deep this should parse
-    threshold:
+    - name: threshold
       default: 1G
       help: Only show directories bigger than this
 command:
diff --git a/scripts/custom.yml b/scripts/custom.yml
index ee0300d7..3ff962da 100644
--- a/scripts/custom.yml
+++ b/scripts/custom.yml
@@ -3,7 +3,7 @@
 description: Run a custom playbook from the inventory
 cli:
   arguments:
-    playbook:
+    - name: playbook
       help: Name of the playbook
 arguments:
   custom: yes
diff --git a/scripts/drupal-config.yml b/scripts/drupal-config.yml
index cd00070e..ef7aa1c9 100644
--- a/scripts/drupal-config.yml
+++ b/scripts/drupal-config.yml
@@ -3,14 +3,14 @@
 description: Quickly configure Drupal sites
 cli:
   arguments:
-    limit:
+    - name: limit
       default: no
       help: The hostname on which to re-reploy Drupal
-    site:
+    - name: site
       default: no
       help: The id of a site
   options:
-    quick:
+    - name: quick
       action: store_true
       default: no
       help: Only Drupal itself, not the CLI or JailKit
diff --git a/scripts/drupal-deploy.yml b/scripts/drupal-deploy.yml
index a0558a32..a34197fe 100644
--- a/scripts/drupal-deploy.yml
+++ b/scripts/drupal-deploy.yml
@@ -3,10 +3,10 @@
 description: Quickly re-deploy a Drupal site
 cli:
   arguments:
-    host:
+    - name: host
       default: no
       help: The hostname on which to re-reploy Drupal
-    site:
+    - name: site
       default: no
       help: The id of a site
 arguments:
diff --git a/scripts/drupal-dump-db.yml b/scripts/drupal-dump-db.yml
index a9ec4d03..5af30d9d 100644
--- a/scripts/drupal-dump-db.yml
+++ b/scripts/drupal-dump-db.yml
@@ -3,13 +3,13 @@
 description: Dump and download Drupal database
 cli:
   arguments:
-    host:
+    - name: host
       default: no
       help: The hostname of the Drupal site
-    site:
+    - name: site
       default: no
       help: The id of a site
-    dumpfilename:
+    - name: dumpfilename
       default: no
       help: The filename of the downloaded dump file
 arguments:
diff --git a/scripts/drupal-launch.yml b/scripts/drupal-launch.yml
index 4400626f..f64e3c69 100644
--- a/scripts/drupal-launch.yml
+++ b/scripts/drupal-launch.yml
@@ -3,10 +3,10 @@
 description: Launch a Drupal site by creating certs, configure HaProxy, Apache and Drupal
 cli:
   arguments:
-    host:
+    - name: host
       default: no
       help: The hostname on which to launch Drupal
-    site:
+    - name: site
       default: no
       help: The id of a site
   defaults:
diff --git a/scripts/firewall-unprotect.yml b/scripts/firewall-unprotect.yml
index d23a3148..642472e5 100644
--- a/scripts/firewall-unprotect.yml
+++ b/scripts/firewall-unprotect.yml
@@ -3,7 +3,7 @@
 description: Switch Firewall to unprotected mode for a period of time
 cli:
   options:
-    unprotect-period:
+    - name: unprotect-period
       default: no
       help: Number of minutes before the firewall goes into protected mode again
 arguments:
diff --git a/scripts/inithost.yml b/scripts/inithost.yml
index 90cdc1eb..8ff88aac 100644
--- a/scripts/inithost.yml
+++ b/scripts/inithost.yml
@@ -3,40 +3,40 @@
 description: Initially setup a new host
 cli:
   arguments:
-    host:
+    - name: host
       help: Name of the host to be created
   options:
-    user:
+    - name: user
       action: store
       default:
         exec: |
           result = os.environ['USER']
       help: The username of the first created admin user
-    root:
+    - name: root
       action: store
       default: root
       help: The username to use initially
-    key:
+    - name: key
       action: store
       help: File name with the private key to be used initially
   groups:
     Cloud:
       description: When installing through a cloud provider, use these options
       options:
-        cloud:
+        - name: cloud
           action: store
           choices:
             - ec2
             - jiffybox
             - linode
           help: The cloud provider
-        groups:
+        - name: groups
           action: store
           help: The inventory groups for the host as comma separated list
     Non Cloud:
       description: When installing directly, use these options
       options:
-        ip:
+        - name: ip
           action: store
           help: The ip address of the host, only required if not installed in the cloud
 arguments:
diff --git a/scripts/initpi.yml b/scripts/initpi.yml
index c27178d1..a801d4c5 100644
--- a/scripts/initpi.yml
+++ b/scripts/initpi.yml
@@ -3,20 +3,20 @@
 description: Initially setup a new Raspberry Pi
 cli:
   arguments:
-    host:
+    - name: host
       help: Name of the Pi to be created
   options:
-    user:
+    - name: user
       action: store
       default:
         exec: |
           result = os.environ['USER']
       help: The username of the first created admin user
-    root:
+    - name: root
       action: store
       default: pi
       help: The username to use initially
-    key:
+    - name: key
       action: store
       help: File name with the private key to be used initially
 arguments:
diff --git a/scripts/jailkit-update.yml b/scripts/jailkit-update.yml
index 9c4c48d6..858fae2a 100644
--- a/scripts/jailkit-update.yml
+++ b/scripts/jailkit-update.yml
@@ -3,7 +3,7 @@
 description: Force updating all Jails
 cli:
   options:
-    site:
+    - name: site
       default: no
       help: The id of a site if only one of the defined sites should be updated
   defaults:
diff --git a/scripts/jailkit-user.yml b/scripts/jailkit-user.yml
index 7df1b1fc..734744d4 100644
--- a/scripts/jailkit-user.yml
+++ b/scripts/jailkit-user.yml
@@ -3,7 +3,7 @@
 description: Init and update users in Jails
 cli:
   options:
-    site:
+    - name: site
       default: no
       help: The id of a site if only one of the defined sites should be updated
   defaults:
diff --git a/scripts/lists.yml b/scripts/lists.yml
index ccea2463..ea2b18e3 100644
--- a/scripts/lists.yml
+++ b/scripts/lists.yml
@@ -3,7 +3,7 @@
 description: Lists hosts and IP addresses
 cli:
   options:
-    ip:
+    - name: ip
       default: no
       help: An optional IP to limit the assertion to that single IP
 arguments:
diff --git a/scripts/localhost.yml b/scripts/localhost.yml
index c063ae8b..c454c5a4 100644
--- a/scripts/localhost.yml
+++ b/scripts/localhost.yml
@@ -4,12 +4,12 @@ description: Update local hosts file and SSH config, then call script hosts
 inventory-given-by-script: yes
 cli:
   options:
-    host:
+    - name: host
       action: store
       default:
         exec: |
           result = socket.gethostname()
-    user:
+    - name: user
       action: store
       default:
         exec: |
diff --git a/scripts/matomo.yml b/scripts/matomo.yml
index 5d27e6e8..56d16564 100644
--- a/scripts/matomo.yml
+++ b/scripts/matomo.yml
@@ -3,11 +3,11 @@
 description: Quickly update matomo sites
 cli:
   options:
-    reset:
+    - name: reset
       action: store_true
       default: no
       help: If True the existing directories get deleted first
-    site:
+    - name: site
       default: no
       help: The id of a site if matomo should be updated only for one of the defined sites
   defaults:
diff --git a/scripts/netdata.yml b/scripts/netdata.yml
index 9a6ccb0c..202276c4 100644
--- a/scripts/netdata.yml
+++ b/scripts/netdata.yml
@@ -3,7 +3,7 @@
 description: Quickly update NetData
 cli:
   options:
-    reset:
+    - name: reset
       action: store_true
       default: no
       help: If True the existing directories get deleted first
diff --git a/scripts/nextcloud-install.yml b/scripts/nextcloud-install.yml
index 92070a6d..034128e8 100644
--- a/scripts/nextcloud-install.yml
+++ b/scripts/nextcloud-install.yml
@@ -3,7 +3,7 @@
 description: Install a new NextCloud site
 cli:
   arguments:
-    site:
+    - name: site
       help: The id of the site to install
   defaults:
     limit: webserver
diff --git a/scripts/nextcloud-plugins.yml b/scripts/nextcloud-plugins.yml
index 214a052f..61cb40d7 100644
--- a/scripts/nextcloud-plugins.yml
+++ b/scripts/nextcloud-plugins.yml
@@ -3,7 +3,7 @@
 description: Quickly update NextCloud plugins
 cli:
   options:
-    site:
+    - name: site
       default: no
       help: The id of a site if plugins should be updated only for one of the defined sites
   defaults:
diff --git a/scripts/nextcloud.yml b/scripts/nextcloud.yml
index ae510bc2..21ed93a3 100644
--- a/scripts/nextcloud.yml
+++ b/scripts/nextcloud.yml
@@ -3,7 +3,7 @@
 description: Quickly update NextCloud sites
 cli:
   options:
-    site:
+    - name: site
       default: no
       help: The id of a site if only one of the defined sites should be updated
   defaults:
diff --git a/scripts/playbook.yml b/scripts/playbook.yml
index e7700f25..1e76550e 100644
--- a/scripts/playbook.yml
+++ b/scripts/playbook.yml
@@ -3,8 +3,8 @@
 description: Run a specific playbook
 cli:
   arguments:
-    playbook:
+    - name: playbook
       help: Playbook to execute
   options:
-    custom:
+    - name: custom
       default: no
diff --git a/scripts/removehost.yml b/scripts/removehost.yml
index 8ca9a94d..e42bf9eb 100644
--- a/scripts/removehost.yml
+++ b/scripts/removehost.yml
@@ -3,10 +3,10 @@
 description: Remove a host and delete the instance in the cloud
 cli:
   arguments:
-    host:
+    - name: host
       help: Name of the host to be removed
   options:
-    cloud:
+    - name: cloud
       action: store
       choices:
         - ec2
diff --git a/scripts/role.yml b/scripts/role.yml
index a87f4f16..a20dbdf7 100644
--- a/scripts/role.yml
+++ b/scripts/role.yml
@@ -3,7 +3,7 @@
 description: Run a specific role only
 cli:
   arguments:
-    role:
+    - name: role
       help: Role to execute
 arguments:
   playbook: role
diff --git a/scripts/sanity.yml b/scripts/sanity.yml
index 0c2dd6b1..845d7747 100644
--- a/scripts/sanity.yml
+++ b/scripts/sanity.yml
@@ -3,7 +3,7 @@
 description: Check for updates, upgrade and reboot hosts
 cli:
   arguments:
-    mode:
+    - name: mode
       choices:
         - check
         - upgrade
@@ -11,11 +11,11 @@ cli:
         - reschedule
       help: Mode for the sanity play
   options:
-    force:
+    - name: force
       action: store_true
       default: no
       help: Force to also reboot proxy servers
-    withoutreason:
+    - name: withoutreason
       action: store_true
       default: no
       help: Force reboot even if not required
diff --git a/scripts/setup-local.yml b/scripts/setup-local.yml
index c1fb9415..01963c3f 100644
--- a/scripts/setup-local.yml
+++ b/scripts/setup-local.yml
@@ -4,10 +4,10 @@ description: Setup and update the Paragon wrapper for Ansible
 ignore-inventory: yes
 cli:
   arguments:
-    inventory:
+    - name: inventory
       help: Name of the company in lowercase to specify the inventory
   options:
-    username:
+    - name: username
       default:
         exec: |
           import ConfigParser
@@ -20,7 +20,7 @@ cli:
           if not result:
               result = os.environ.get('USER')
       help: Name of the remote user if different from your local username
-    skip-os-tasks:
+    - name: skip-os-tasks
       action: store_false
       default: yes
       help: Skip all tasks that aim to install os components in order to do that manually
diff --git a/scripts/userlock.yml b/scripts/userlock.yml
index 181aad11..dfac3d44 100644
--- a/scripts/userlock.yml
+++ b/scripts/userlock.yml
@@ -3,7 +3,7 @@
 description: Lock user on all hosts
 cli:
   arguments:
-    lockuser_username:
+    - name: lockuser_username
       help: Existing username who should be locked
   defaults:
     limit: all
diff --git a/scripts/userpwd.yml b/scripts/userpwd.yml
index 73d07cf3..b74d572b 100644
--- a/scripts/userpwd.yml
+++ b/scripts/userpwd.yml
@@ -3,9 +3,9 @@
 description: Set user password on all hosts
 cli:
   arguments:
-    username:
+    - name: username
       help: Existing username for whom to set a new password
-    password:
+    - name: password
       help: New password for the given user
   defaults:
     limit: all
diff --git a/scripts/userunlock.yml b/scripts/userunlock.yml
index f885d2f1..f624582b 100644
--- a/scripts/userunlock.yml
+++ b/scripts/userunlock.yml
@@ -3,7 +3,7 @@
 description: Unlock user on all hosts
 cli:
   arguments:
-    lockuser_username:
+    - name: lockuser_username
       help: Existing username who should be unlocked
   defaults:
     limit: all
-- 
GitLab