diff --git a/.kitchen.yml b/.kitchen.yml index 41b0c84..1a36fd6 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -1,52 +1,68 @@ --- driver : - name : localhost + # TRAVIS: local + # NO TRAVIS: vagrant + name : <%= if ENV['TRAVIS'] then 'localhost' else 'vagrant' end %> provisioner: name : ansible_push verbose : "vvvv" ansible_config : "test/ansible.cfg" idempotency_test : True - sudo : True - + # TRAVIS: True + # NO TRAVIS: False + sudo : <%= if ENV['TRAVIS'] then 'True' else 'False' end %> platforms: - - name : travis - provisioner : - raw_arguments : "-c local" + # travistravis + - name : <%= if ENV['TRAVIS'] then 'travis' else 'ubuntu-14.04' end %> + provisioner : + raw_arguments : <%= if ENV['TRAVIS'] then '-c local' else '' end %> + # Should be safily ignored by Travis since connection local + driver: + box: ubuntu/trusty64 + customize: + cpus : 2 + memory : 2048 + suites: - name : group provisioner : playbook : "test/application/group.yml" - extra_vars : { 'kitchen_connection': 'smart' } + extra_vars : { 'kitchen_connection': 'smart', 'kitchen_hosts': '<%= if ENV['TRAVIS'] then 'localhost' else 'all' end %>' } - name : simple provisioner : playbook : "test/application/simple.yml" - extra_vars : { 'kitchen_connection': 'smart' } + extra_vars : { 'kitchen_connection': 'smart', 'kitchen_hosts': '<%= if ENV['TRAVIS'] then 'localhost' else 'all' end %>' } - name : advanced provisioner : playbook : "test/application/advanced.yml" - extra_vars : { 'kitchen_connection': 'smart' } + extra_vars : { 'kitchen_connection': 'smart', 'kitchen_hosts': '<%= if ENV['TRAVIS'] then 'localhost' else 'all' end %>' } - name : source-files provisioner : playbook : "test/application/source_files.yml" - extra_vars : { 'kitchen_connection': 'smart' } + extra_vars : { 'kitchen_connection': 'smart', 'kitchen_hosts': '<%= if ENV['TRAVIS'] then 'localhost' else 'all' end %>' } - name : source-databag provisioner : playbook : "test/application/source_databag.yml" - extra_vars : { 'kitchen_connection': 'smart' } + extra_vars : { 'kitchen_connection': 'smart', 'kitchen_hosts': '<%= if ENV['TRAVIS'] then 'localhost' else 'all' end %>' } - name : multi-source-files provisioner : playbook : "test/application/multi_source_files.yml" - extra_vars : { 'kitchen_connection': 'smart' } + extra_vars : { 'kitchen_connection': 'smart', 'kitchen_hosts': '<%= if ENV['TRAVIS'] then 'localhost' else 'all' end %>' } - name : team provisioner : playbook : "test/application/team.yml" - extra_vars : { 'kitchen_connection': 'smart' } + extra_vars : { 'kitchen_connection': 'smart', 'kitchen_hosts': '<%= if ENV['TRAVIS'] then 'localhost' else 'all' end %>' } + + - name : extra-simple + provisioner : + playbook : "test/application/exta_simple.yml" + extra_vars : { 'kitchen_connection': 'smart', 'kitchen_hosts': '<%= if ENV['TRAVIS'] then 'localhost' else 'all' end %>' } \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 39ecbc5..7263707 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,7 @@ install: script: - ansible --version + - export TRAVIS=True - bundle install - bundle exec kitchen test travis diff --git a/Gemfile b/Gemfile index 255c80a..9c03545 100644 --- a/Gemfile +++ b/Gemfile @@ -2,10 +2,8 @@ source 'https://rubygems.org' group :development do - # Use Berkshelf for resolving cookbook dependencies - gem 'test-kitchen' gem 'kitchen-vagrant' gem 'kitchen-ansiblepush' gem 'kitchen-localhost' -end \ No newline at end of file +end diff --git a/library/usersdb.py b/library/usersdb.py index 8135f60..8a8618b 100644 --- a/library/usersdb.py +++ b/library/usersdb.py @@ -1,11 +1,16 @@ #!/usr/bin/python +USERVALUES = [ 'append', 'comment', 'createhome', 'expires', 'force', 'generate_ssh_key', 'group', 'groups', 'home', + 'login_class', 'move_home', 'name', 'non_unique', 'password', 'remove', 'shell', 'skeleton', 'ssh_key_bits', + 'ssh_key_comment', 'ssh_key_file', 'ssh_key_passphrase', 'ssh_key_type', 'state', 'system', 'uid', 'update_password', + 'keys'] class UsersDB(object): def __init__(self, module): self.module = module self.users_db = self.module.params["usersdb"] self.source_user_db = self.module.params["source_userdb"] + self.extract_extra_keys = self.module.params["extract_extra_keys"] # If we have to userdb and source db lets merge them if not if self.users_db and self.source_user_db: self.users_db.update(self.source_user_db) @@ -22,6 +27,7 @@ def __init__(self, module): self.expanded_users_key_db = [] # Used in simple mode self.expanded_server_db = [] # Used in advanced mode for merged User + server self.expanded_server_key_db = [] # Used in advanced mode + self.extra_users_data = [] # Used for extra data that is not related to user module def _concat_keys(self, user_name, user_keys=None, server_keys=None, user_status=False): # Concat keys (if possible) and update username to keys @@ -153,15 +159,31 @@ def expand_users(self): # Get User database which is a dic and create expendaded_user_db and key_db # Put keys in right dictionary format for username, user_options in self.users_db.iteritems(): - # 1- Convert dic to list (servers_db style) user = {"name": username} # create the account name + + # 1- Check for extra keys that dont translate to ansible user module + if self.extract_extra_keys: + extra_user_data = None + for dic_key in user_options.keys(): + if dic_key not in USERVALUES: + # Add user and state + if not extra_user_data: + extra_user_data = dict(user) + extra_user_data.update({ "state": user_options.get("state", "present")}) + + extra_user_data.update({ dic_key: user_options[dic_key] }) + user_options.pop(dic_key, None) # Remove item from user DB + # Add extras to a list if any + if extra_user_data: + self.extra_users_data.append(dict(extra_user_data)) + # 2- Convert dic to list (servers_db style) user.update(user_options) # update all other option - # 2- Compile key + # 3- Compile key unformatted_keys = user_options.get("keys", []) keys = self.expand_keys(unformatted_keys, user) - # 3- remove keys from userdb if exists + # 4- remove keys from userdb if exists user.pop("keys", None) - # 4- Populate DBs + # 5- Populate DBs self.expanded_users_db.append(user) # Populate new list user db self.expanded_users_key_db.append({"user": username, "keys": keys}) if len(keys) > 0: @@ -181,6 +203,11 @@ def main(self): result = {"changed": False, "msg": "", "users_db": self.expanded_users_db, "key_db": self.expanded_users_key_db} + + # Add extras if options + if self.extract_extra_keys: + result.update({ "extra" : self.extra_users_data }) + self.module.exit_json(**result) @@ -191,6 +218,7 @@ def main(): source_userdb=dict(default=None, required=False, type="dict"), teamsdb=dict(default=None, required=False), # Should be dict but would break if value is false/none serversdb=dict(default=None, required=False), + extract_extra_keys=dict(default=True, required=False), ), supports_check_mode=False ) diff --git a/tasks/debug.yml b/tasks/debug.yml index f7d3991..2aee9d1 100644 --- a/tasks/debug.yml +++ b/tasks/debug.yml @@ -12,6 +12,12 @@ sudo: no when: usermanage_debug_level >= 2 +- name: debug | Display Extra + debug: + var=cuser.extra + sudo: no + when: usermanage_debug_level >= 2 + - name: debug | Display lookup_key_db keys debug: var=cuser.lookup_key_db diff --git a/test/.kitchen.yml b/test/.kitchen.yml deleted file mode 100644 index e69c2c0..0000000 --- a/test/.kitchen.yml +++ /dev/null @@ -1,22 +0,0 @@ ---- - -# this file is used to simulate travis -driver: - name: vagrant - -provisioner: - name: shell - script: run_vagrant_kitchen.sh - -platforms: - - name: ubuntu-14.04 - driver: - box: ubuntu/trusty64 - synced_folders: - - [ '/Users/helal/Documents/Projects/ansible-usermanage/' , '/mnt/shared/ansible-usermanage/' ] - -suites: - - name: default - - -# - ["<% File.expand_path('../',File.expand_path('../', Dir.pwd))%>", "<%= '/mnt/shared/' + File.basename(File.expand_path('../', Dir.pwd)) %>/"] \ No newline at end of file diff --git a/test/application/advanced.yml b/test/application/advanced.yml index f29d086..b1e0364 100644 --- a/test/application/advanced.yml +++ b/test/application/advanced.yml @@ -1,6 +1,6 @@ --- - name : Advanced Mode (1) - hosts : localhost + hosts : "{{ kitchen_hosts }}" gather_facts : no sudo : True connection : "{{ kitchen_connection | default('local') }}" diff --git a/test/application/exta_simple.yml b/test/application/exta_simple.yml new file mode 100644 index 0000000..313ebdc --- /dev/null +++ b/test/application/exta_simple.yml @@ -0,0 +1,26 @@ +--- +- name : Extra user info Simple Mode (1) + hosts : "{{ kitchen_hosts }}" + gather_facts : no + sudo : True + connection : "{{ kitchen_connection | default('local') }}" + vars : + usermanage_debug : true + vars_files : + - "extra_var_simple_db.yml" + pre_tasks : + - debug: var=kitchen_connection + roles : + - "ansible-usermanage" + post_tasks : + + - name: Print the user db in a yaml file + copy: + content="{{ cuser.users_db | to_yaml }}" + dest="/tmp/extra_simple_users_db.yaml" + + - name: Print the extra user options in a yaml file + copy: + content="{{ cuser.extra | to_yaml }}" + dest="/tmp/extra_simple_extra_db.yaml" + diff --git a/test/application/extra_var_simple_db.yml b/test/application/extra_var_simple_db.yml new file mode 100644 index 0000000..83db894 --- /dev/null +++ b/test/application/extra_var_simple_db.yml @@ -0,0 +1,39 @@ +--- +usermanage_usersdb: + daniels2: + comment: "Jack daniels" + keys: + - key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDLql1khoXEH/pThpLSDwJNBIEHkjrBggjEvRCqCFYvE1Neavc6iuLSzjLdnj74LNrPEjY+xcjAcPmgwxo8+WKpLL7Iy8e9IGH3lwB05x9jfnw2H1ZRnZZxF+wV/ei/vfCmRyt2cqv+DLomg18RDTnyTk2pvSEvL0xkRn5QRbzxqbnB+9xmItTjdtq/ZDYRgFYn2ZPfokFyyr3KpwpK0gNcpFhCF94CvExKpu6SFPTv+ERnFvHEN9d8SlzwkyCP4yqrfOjFuVUuZf2FtAkDx0d4cXo0i7VUM/hOthUNFpmljZLhkxafPxwp50Q/xRe7MvDQMrEPGPZ/pubOwzqVmMWH" + - key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCxAqbTlltSFlRY+gQyAx3j0W+WDnahZYbECAXiwNqAHG7PP8GSEDVkfZTkJdlu9PoB/B3nW2R/Q3//IxUfzRsUnjUzl0WXbhz331n5bHtgJlg82MGqwbNjN0yMR/GB4pQKeExYOLKi/7jI/wkOAJ4X9Bv9skEK/mHAWWPrBf/5C5qWUOxVC1+he3iaU+LSbiL6uiNs8S49fiGno8tBkBFgth+9gqdCLRAFVe2dzJJK1nSQTffHCs12pJs2S3yBD9KkUQJO51tByP4qO3549iwLo8hQnqtFULMpL+NN5Muk1bFZ2jW+0Sri1bhVS58llZCuoENZsLf/+xejbfwJAk4h" + key_options: no-port-forwarding + gin2: + comment: "Gordons Gin" + keys: + - key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCcoo+eU8+k7QYpKbZwOQwiMpeklQcmEyLTsJr0RLTeqsHkIh8rFWyMZURDZ5pgEGo3iXZD+dqM28agy2Pw68/V0wht/9n0PjmUVZgkWIas162w3vZrJENDi8wAo4ojQJf0lZf63K8AxoB12fF+QdR7jfTLrz2bCxv9XaHKm7nYGtRO0f8ETgvwpIS2jN0mPAD7qnCFvLtbaxd/UzsQS5M8Au42+9zdn78Atm7gtKY9uR5U1Jwrop8KipXf0wAtMo39Xc9P8hGbYGA1jkbcG2x1LI7G9L+PddxeZjpkW2Uv559YJDRjBJfJAfp6K4HGV5uXITSMVDY9KBYvepolrlul" + shell: /bin/false + rum2: + comment: "Pirates Grog Rum" + keys: + - key: "ssh-rsa AAAAB3NzaC2EAA1ycAADAAAQABABAQCootXD63hexEQnbCmKGC7DjFSWxkqJ2neaC5S6POEdgwo7jQ60JWy0VCm5JS5d2ZNDQh+vi1wZ2cTr6n9X9bAkYhQ/eACmzYBjf8I8AXcqaigAOjRMLADU2qQfZmnRGyOLaGDI/EH52yBjeZHbgQdJOGrB07qgAu2facA2bd6kvI8eLwCx5yjqA+mInYEewRYrr5tUduGFdPhmyoKSGpaEeWWkLhafTj9eGRMSB3unBcMtux+LxXH4TfWgVBmWNVbr2Mcv+M6tYxix/iKniBLBUH/AfM/dTHlk38y2mjemUMUc/HBW+HmH3NXMwOks8po6Iohh8JNhywUlLKN9MvB7" + state: absent + stewart2: + comment: "Daniel Stewart" + home: /opt/stewart + keys: + - key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDhiDPE4S4K6AGJFRSIB5xVoIlKtgjVUVHK1WhT0hD/I3nZ3AFszqDXUz4eREDlPSfMsvNCuAd1Mxwg2vx1Udbzf0M5OH1DDgYyVeJXXB5/B2rpX7vm0A1Hxx17mMHg9OrCNKNn8B83g6IqAGM6P3VKHqnRQ9kLpPcki65gMx06R2dQ1Dh5kks2yOjyx7Mjut0rL9Ig/b9ysMMC1YjMupC8vb31Dhy8pVi1F/RT/7M6PwM4Kjh3fdzgqvQRxDrmky8kbXJj+TXU6pIM1mZtZyENddUCA0rDNtpi6yIaAR9aJkcPXxPpblkWjYAO++sukz88BKWt0Z+nLx9JUhwXtoW7" + vodaka2: + comment: "Savvy Vodka" + keys: + - key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC2Pq3M7AgeBjmNII6HGsKd2uaXFIfaljpNg1Rf6y3iGP84wC82bMfZTSIhnzJ4qwHj7Bzn8oiMmqtyeGcmEwLXm5f7mk3lj9NmxUEfbuWsPoSX4VHIney0F2cjrYRAHua8vZ50OrqYvRaBNttx+pCsub/Kw/t91PQvz7s5ML12DfhlfbE5f/g+ZrKHBxsn6Vw0VqN1Cx5cecaN+9NbdwTV25/RVsXC6v9TQlIqWR+znt4ZVxUSCTAbGc51tmauoleZee2XBkAO7xmJ7zPQEndhErq/zm0euZGx1xGIjQ7dVBK8t1ah2UdBS4pSHgjhDulo0hr4gIubQ0FSV+8cWCNN" + uid: 5300 + vpn: true + raki2: + state: "absent" + comment: "Yeni Raki" + keys: + - key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCvy3wrbh9hwSP0WrwXSFW4AujinW+xiDQn7RLJ8UcVZ+Yf4EmV6GTvjjJjIegIKjnH2xiRDjZ1qaSZzxW7/uyVxPrjhGAE8iPQAGcLEEcpg4IwlFpd3+7NgCKLdVHozH6z+h3G95otKQZLmKq9lzkfVyhDzTjU2qsnSQPitDrPY/tngN1gnZHQm2CUh4gamtOfxtPKlOqQ/t0iXJU48QfyN33XWr8M5/2FWP9jDyvxEjpCRW2Qu2+8uQONPOHMtkLW70G2+KVN90fkOXMnDotm+aY1OluUcXgrBakEctHNIWoKSUbcdOw1JkLY3Ojl11lIdXn267A1t70FaEXG8cIf" + uid: 5400 + aws: true + aws_group: Admin + brad2: + comment: "Brad" diff --git a/test/application/group.yml b/test/application/group.yml index afb2800..df511d0 100644 --- a/test/application/group.yml +++ b/test/application/group.yml @@ -1,6 +1,6 @@ --- - name : Group (1) - hosts : localhost + hosts : "{{ kitchen_hosts }}" gather_facts : no sudo : True connection : "{{ kitchen_connection | default('local') }}" diff --git a/test/application/multi_source_files.yml b/test/application/multi_source_files.yml index 4e5caee..234861c 100644 --- a/test/application/multi_source_files.yml +++ b/test/application/multi_source_files.yml @@ -1,6 +1,6 @@ --- - name : Multi Sources files - hosts : localhost + hosts : "{{ kitchen_hosts }}" gather_facts : no sudo : True connection : "{{ kitchen_connection | default('local') }}" diff --git a/test/application/simple.yml b/test/application/simple.yml index dbc4c9d..6220302 100644 --- a/test/application/simple.yml +++ b/test/application/simple.yml @@ -1,6 +1,6 @@ --- - name : Simple Mode (1) - hosts : localhost + hosts : "{{ kitchen_hosts }}" gather_facts : no sudo : True connection : "{{ kitchen_connection | default('local') }}" diff --git a/test/application/source_databag.yml b/test/application/source_databag.yml index 69585b6..d378dd4 100644 --- a/test/application/source_databag.yml +++ b/test/application/source_databag.yml @@ -1,6 +1,6 @@ --- - name : Sources databag - hosts : localhost + hosts : "{{ kitchen_hosts }}" gather_facts : no sudo : True connection : "{{ kitchen_connection | default('local') }}" diff --git a/test/application/source_files.yml b/test/application/source_files.yml index ef6ad18..d82f548 100644 --- a/test/application/source_files.yml +++ b/test/application/source_files.yml @@ -1,6 +1,6 @@ --- - name : Sources files - hosts : localhost + hosts : "{{ kitchen_hosts }}" gather_facts : no sudo : True connection : "{{ kitchen_connection | default('local') }}" diff --git a/test/application/team.yml b/test/application/team.yml index b10890d..939a108 100644 --- a/test/application/team.yml +++ b/test/application/team.yml @@ -1,6 +1,6 @@ --- - name : Team (1) - hosts : localhost + hosts : "{{ kitchen_hosts }}" gather_facts : no sudo : True connection : "{{ kitchen_connection | default('local') }}" diff --git a/test/integration/extra-simple/serverspec/test_spec.rb b/test/integration/extra-simple/serverspec/test_spec.rb new file mode 100644 index 0000000..ef155e0 --- /dev/null +++ b/test/integration/extra-simple/serverspec/test_spec.rb @@ -0,0 +1,57 @@ +require 'serverspec' +require 'yaml' + + +# Required by serverspec +set :backend, :exec + +describe user('daniels2') do + it { should exist } + it { should have_authorized_key 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDLql1khoXEH/pThpLSDwJNBIEHkjrBggjEvRCqCFYvE1Neavc6iuLSzjLdnj74LNrPEjY+xcjAcPmgwxo8+WKpLL7Iy8e9IGH3lwB05x9jfnw2H1ZRnZZxF+wV/ei/vfCmRyt2cqv+DLomg18RDTnyTk2pvSEvL0xkRn5QRbzxqbnB+9xmItTjdtq/ZDYRgFYn2ZPfokFyyr3KpwpK0gNcpFhCF94CvExKpu6SFPTv+ERnFvHEN9d8SlzwkyCP4yqrfOjFuVUuZf2FtAkDx0d4cXo0i7VUM/hOthUNFpmljZLhkxafPxwp50Q/xRe7MvDQMrEPGPZ/pubOwzqVmMWH' } + it { should have_authorized_key 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCxAqbTlltSFlRY+gQyAx3j0W+WDnahZYbECAXiwNqAHG7PP8GSEDVkfZTkJdlu9PoB/B3nW2R/Q3//IxUfzRsUnjUzl0WXbhz331n5bHtgJlg82MGqwbNjN0yMR/GB4pQKeExYOLKi/7jI/wkOAJ4X9Bv9skEK/mHAWWPrBf/5C5qWUOxVC1+he3iaU+LSbiL6uiNs8S49fiGno8tBkBFgth+9gqdCLRAFVe2dzJJK1nSQTffHCs12pJs2S3yBD9KkUQJO51tByP4qO3549iwLo8hQnqtFULMpL+NN5Muk1bFZ2jW+0Sri1bhVS58llZCuoENZsLf/+xejbfwJAk4h' } +#TODO: second key should have #key_options: no-port-forwarding +end + +describe user('gin2') do + it { should exist } + it { have_login_shell '/bin/false' } + it { should have_authorized_key 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCcoo+eU8+k7QYpKbZwOQwiMpeklQcmEyLTsJr0RLTeqsHkIh8rFWyMZURDZ5pgEGo3iXZD+dqM28agy2Pw68/V0wht/9n0PjmUVZgkWIas162w3vZrJENDi8wAo4ojQJf0lZf63K8AxoB12fF+QdR7jfTLrz2bCxv9XaHKm7nYGtRO0f8ETgvwpIS2jN0mPAD7qnCFvLtbaxd/UzsQS5M8Au42+9zdn78Atm7gtKY9uR5U1Jwrop8KipXf0wAtMo39Xc9P8hGbYGA1jkbcG2x1LI7G9L+PddxeZjpkW2Uv559YJDRjBJfJAfp6K4HGV5uXITSMVDY9KBYvepolrlul' } +end + +describe user('rum2') do + it { should exist } + it { should_not have_authorized_key 'ssh-rsa AAAAB3NzaC2EAA1ycAADAAAQABABAQCootXD63hexEQnbCmKGC7DjFSWxkqJ2neaC5S6POEdgwo7jQ60JWy0VCm5JS5d2ZNDQh+vi1wZ2cTr6n9X9bAkYhQ/eACmzYBjf8I8AXcqaigAOjRMLADU2qQfZmnRGyOLaGDI/EH52yBjeZHbgQdJOGrB07qgAu2facA2bd6kvI8eLwCx5yjqA+mInYEewRYrr5tUduGFdPhmyoKSGpaEeWWkLhafTj9eGRMSB3unBcMtux+LxXH4TfWgVBmWNVbr2Mcv+M6tYxix/iKniBLBUH/AfM/dTHlk38y2mjemUMUc/HBW+HmH3NXMwOks8po6Iohh8JNhywUlLKN9MvB7' } +end + +describe user('stewart2') do + it { should exist } + it { should have_home_directory '/opt/stewart' } + it { should have_authorized_key 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDhiDPE4S4K6AGJFRSIB5xVoIlKtgjVUVHK1WhT0hD/I3nZ3AFszqDXUz4eREDlPSfMsvNCuAd1Mxwg2vx1Udbzf0M5OH1DDgYyVeJXXB5/B2rpX7vm0A1Hxx17mMHg9OrCNKNn8B83g6IqAGM6P3VKHqnRQ9kLpPcki65gMx06R2dQ1Dh5kks2yOjyx7Mjut0rL9Ig/b9ysMMC1YjMupC8vb31Dhy8pVi1F/RT/7M6PwM4Kjh3fdzgqvQRxDrmky8kbXJj+TXU6pIM1mZtZyENddUCA0rDNtpi6yIaAR9aJkcPXxPpblkWjYAO++sukz88BKWt0Z+nLx9JUhwXtoW7' } +end + +describe user('vodaka2') do + it { should exist } + it { should have_uid 5300 } + it { should have_authorized_key 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC2Pq3M7AgeBjmNII6HGsKd2uaXFIfaljpNg1Rf6y3iGP84wC82bMfZTSIhnzJ4qwHj7Bzn8oiMmqtyeGcmEwLXm5f7mk3lj9NmxUEfbuWsPoSX4VHIney0F2cjrYRAHua8vZ50OrqYvRaBNttx+pCsub/Kw/t91PQvz7s5ML12DfhlfbE5f/g+ZrKHBxsn6Vw0VqN1Cx5cecaN+9NbdwTV25/RVsXC6v9TQlIqWR+znt4ZVxUSCTAbGc51tmauoleZee2XBkAO7xmJ7zPQEndhErq/zm0euZGx1xGIjQ7dVBK8t1ah2UdBS4pSHgjhDulo0hr4gIubQ0FSV+8cWCNN' } +end + +describe user('raki2') do + it { should_not exist } +end + +describe "Database match" do + + it "extra variables" do + expected_hash = [{"state"=>"present", "vpn"=>true, "name"=>"vodaka2"}, {"state"=>"absent", "aws"=>true, "aws_group"=>"Admin", "name"=>"raki2"}] + given_hash = YAML.load_file('/tmp/extra_simple_extra_db.yaml') + expect(given_hash).to match(expected_hash) + end + + it "users variables" do + expected_hash = [{"comment"=>"Brad", "name"=>"brad2"}, {"comment"=>"Daniel Stewart", "home"=>"/opt/stewart", "name"=>"stewart2"}, {"comment"=>"Jack daniels", "name"=>"daniels2"}, {"comment"=>"Gordons Gin", "name"=>"gin2", "shell"=>"/bin/false"}, {"comment"=>"Pirates Grog Rum", "name"=>"rum2"}, {"comment"=>"Savvy Vodka", "name"=>"vodaka2", "uid"=>5300}, {"comment"=>"Yeni Raki", "name"=>"raki2", "state"=>"absent", "uid"=>5400}] + given_hash = YAML.load_file('/tmp/extra_simple_users_db.yaml') + print given_hash + expect(given_hash).to match(expected_hash) + end + +end \ No newline at end of file diff --git a/test/local.ini b/test/local.ini deleted file mode 100644 index aa9e304..0000000 --- a/test/local.ini +++ /dev/null @@ -1 +0,0 @@ -localhost ansible_connection='local' diff --git a/test/run_vagrant_kitchen.sh b/test/run_vagrant_kitchen.sh deleted file mode 100644 index f7180ce..0000000 --- a/test/run_vagrant_kitchen.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash -set -e -echo "**** Box setup ***" - -echo "* mkdir /kitchen" -mkdir -p /kitchen - -#echo "* cp -ar /mnt/shared /kitchen" -#cp -r /mnt/shared/. /kitchen -echo "* ln -sf /mnt/shared /kitchen" -ln -sf /mnt/shared/* /kitchen/ - -echo "* cd /kitchen" -cd /kitchen/* - -echo "* python test/travis_run.py" -python test/travis_run.py - diff --git a/test/travis_run.py b/test/travis_run.py deleted file mode 100644 index 9ab6ba4..0000000 --- a/test/travis_run.py +++ /dev/null @@ -1,98 +0,0 @@ -#!/usr/bin/env python -# https://github.com/ahelal/travis-in-box - -import yaml -import subprocess -import sys -import os.path - - -class TravisExec(object): - def __init__(self, filename="travis.yml"): - self.fail = False - stream = open(filename, 'r') - yaml_file = yaml.load(stream) - # language - self.language = yaml_file.get("language", None) - - # Section - self.section_before_install = yaml_file.get("before_install", None) - self.section_install = yaml_file.get("install", None) - self.section_before_script = yaml_file.get("before_script", None) - self.section_script = yaml_file.get("script", None) - - #self.section_after_script = yaml_file.get("after_script", None) - self.section_after_failure = yaml_file.get("after_failure", None) - self.section_after_success = yaml_file.get("after_success", None) - - def _setup(self): - if self.language == "python": - print "********** Setup Python **********" - print "" - # Since we are not using container we have to install various lang our self - # So this is probably not the best way to do it - self._execute_command(["sudo apt-get install python-setuptools python-pip -y"]) - else: - print "Errors unsupported language {}".format(self.language) - exit(1) - - def life_cycle(self): - # See http://docs.travis-ci.com/user/build-configuration/ - - # 1. setup language - self._setup() - # 4. Run before_install commands - self.run_command("before_install", self.section_before_install, self.section_after_failure) - # 5. Run install commands - self.run_command("install", self.section_install, self.section_after_failure) - # 6. Run before_script commands - self.run_command("before_script", self.section_before_script, self.section_after_failure) - # 7. Run test script commands - self.run_command("script", self.section_script, self.section_after_failure) - # 8 . if we reach this point we made it run after_success - self.run_command("after_success", self.section_after_success, None) - - @staticmethod - def _execute_command(command): - new_command = ["echo '> " + item.rstrip('\n') + "' && { " + item.rstrip('\n') + " ; }" for item in command] - new_command = " && ".join(new_command) - - p = subprocess.Popen(new_command, shell=True, stderr=subprocess.PIPE) - while True: - out = p.stderr.read(1) - if out == '' and p.poll() is not None: - break - if out != '': - sys.stdout.write(out) - sys.stdout.flush() - print "" - return p.returncode - - def run_command(self, section_name=None, command=None, execute_on_failure=None): - if command: - print "" - print "********** Running '{}' **********".format(section_name) - return_code = self._execute_command(command) - if return_code != 0: - print "" - print "********** Failed in '{}' **********".format(section_name) - if execute_on_failure: - print "" - print "********** Running after_failure **********".format(section_name) - self._execute_command(execute_on_failure) - exit(1) - -filename = None -if len(sys.argv) == 1: - filename = ".travis.yml" -elif len(sys.argv) == 2: - filename = sys.argv[1] -else: - print "Invalid number of arguments" - exit(1) - -if os.path.exists(filename): - TravisExec(filename).life_cycle() -else: - print "Could not file travis file '{}'".format(filename) - exit(1)