Skip to content

Commit

Permalink
Merge pull request #11 from AutomationWithAnsible/feature/v2_support
Browse files Browse the repository at this point in the history
Feature/v2 support
  • Loading branch information
ahelal committed Dec 19, 2015
2 parents c3d0928 + c28db01 commit 69d11cb
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 101 deletions.
110 changes: 49 additions & 61 deletions .kitchen.yml
Original file line number Diff line number Diff line change
@@ -1,78 +1,66 @@
---
driver :
# TRAVIS: local
# NO TRAVIS: vagrant
name : <%= if ENV['TRAVIS'] then 'localhost' else 'vagrant' end %>
driver :
name : <%= if ENV['TRAVIS'] then 'localhost' else 'vagrant' end %>
box : "ubuntu/trusty64"
customize :
cpus : 2
memory : 2048

provisioner:
name : ansible_push
verbose : "vvvv"
ansible_config : "test/ansible.cfg"
idempotency_test : True
# TRAVIS: True
# NO TRAVIS: False
sudo : <%= if ENV['TRAVIS'] then 'True' else 'False' end %>
name : ansible_push
verbose : "vvvv"
ansible_config : "test/ansible.cfg"
idempotency_test : True
sudo : <%= if ENV['TRAVIS'] then 'True' else 'False' end %>
raw_arguments : <%= if ENV['TRAVIS'] then '-c local' else '' end %>
extra_vars : { 'kitchen_connection': '<%= if ENV["TRAVIS"] then "local" else "smart" end %>', 'kitchen_hosts': '<%= if ENV["TRAVIS"] then "localhost" else "all" end %>' }

platforms:
# 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
- name : "ubuntu-v1"
provisioner :
ansible_playbook_bin : "ansible-version set v1 > /dev/null && ansible-playbook"

- name : "ubuntu-v2"
provisioner :
ansible_playbook_bin : "ansible-version set v2 > /dev/null && ansible-playbook"

suites:
- name : group
provisioner :
playbook : "test/application/group.yml"
extra_vars : { 'kitchen_connection': 'smart', 'kitchen_hosts': '<%= if ENV['TRAVIS'] then 'localhost' else 'all' end %>' }
- name : group
provisioner :
playbook : "test/application/group.yml"

- name : simple
provisioner :
playbook : "test/application/simple.yml"
extra_vars : { 'kitchen_connection': 'smart', 'kitchen_hosts': '<%= if ENV['TRAVIS'] then 'localhost' else 'all' end %>' }
- name : simple
provisioner :
playbook : "test/application/simple.yml"

- name : advanced
provisioner :
playbook : "test/application/advanced.yml"
extra_vars : { 'kitchen_connection': 'smart', 'kitchen_hosts': '<%= if ENV['TRAVIS'] then 'localhost' else 'all' end %>' }
- name : advanced
provisioner :
playbook : "test/application/advanced.yml"

- name : source-files
provisioner :
playbook : "test/application/source_files.yml"
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"

- name : source-databag
provisioner :
playbook : "test/application/source_databag.yml"
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"

- name : multi-source-files
provisioner :
playbook : "test/application/multi_source_files.yml"
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"

- name : team
provisioner :
playbook : "test/application/team.yml"
extra_vars : { 'kitchen_connection': 'smart', 'kitchen_hosts': '<%= if ENV['TRAVIS'] then 'localhost' else 'all' end %>' }
- name : team
provisioner :
playbook : "test/application/team.yml"

- name : extra-simple
provisioner :
playbook : "test/application/extra_simple.yml"
extra_vars : { 'kitchen_connection': 'smart', 'kitchen_hosts': '<%= if ENV['TRAVIS'] then 'localhost' else 'all' end %>' }
- name : extra-simple
provisioner :
playbook : "test/application/extra_simple.yml"

- name : extra-advanced
provisioner :
playbook : "test/application/extra_advanced.yml"
extra_vars : { 'kitchen_connection': 'smart', 'kitchen_hosts': '<%= if ENV['TRAVIS'] then 'localhost' else 'all' end %>' }
- name : extra-advanced
provisioner :
playbook : "test/application/extra_advanced.yml"

- name : extra-team
provisioner :
playbook : "test/application/extra_team.yml"
extra_vars : { 'kitchen_connection': 'smart', 'kitchen_hosts': '<%= if ENV['TRAVIS'] then 'localhost' else 'all' end %>' }
- name : extra-team
provisioner :
playbook : "test/application/extra_team.yml"
17 changes: 10 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
---
dist: trusty
sudo: required
language: python
python: "2.7"

before_install:
# Make sure everything's up to date.
- sudo apt-get update -qq
- sudo apt-get install -qq python-apt python-pycurl git python-pip ruby ruby-dev build-essential autoconf
- gem install bundler
- sudo apt-get install -qq ruby ruby-dev build-essential
- cd /tmp
- git clone https://github.com/AutomationWithAnsible/ansible-setup.git

install:
- sudo pip install ansible
- /tmp/ansible-setup/example/travis-test.sh
- cd $TRAVIS_BUILD_DIR/
- gem install bundler
- bundle install

script:
- ansible --version
- export TRAVIS=True
- bundle install
- bundle exec kitchen test travis
- bundle exec kitchen test

after_success:
- echo "Success"
31 changes: 19 additions & 12 deletions library/load_user_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def _read_from_file(self, file_path, databag):
return data

def convert_chef_user_data_bag(self, data):
print(("data=", data))
if len(data) == 0:
return data
else:
Expand Down Expand Up @@ -106,28 +105,36 @@ def convert_chef_user_data_bag(self, data):

def _check_variable(self):
for path_item in self.path:

try:
path = path_item.get("path")
path = os.path.expanduser(path)
base_path = path_item.get("base_path", None)
databag = path_item.get("databag", self.data_bag)
#print "all={} type={} path={} databag={}".format(path_item, type(path_item), path, databag)
except Exception as E:
self.module.fail_json(msg="Path is a list but is malformed could not get 'path' got '{}'. Error '{}'".
format(path_item, E))
self._follow_path(path, databag)
self._follow_path(path, databag, base_path)

def _follow_path(self, path, databag):
if os.path.exists(path):
if os.path.isdir(path):
for root, dirs, files in os.walk(path, topdown=False):
for filename in files:
self.file_data.update(self._read_from_file(path + "/" + filename, databag))
else:
self.file_data.update(self._read_from_file(path, databag))
def _load_files(self,actual_path, databag):
if os.path.isdir(actual_path):
for root, dirs, files in os.walk(actual_path, topdown=False):
for filename in files:
self.file_data.update(self._read_from_file(actual_path + "/" + filename, databag))
else:
self.module.fail_json(msg="Failed to find path '{}'.".format(path))
self.file_data.update(self._read_from_file(path, databag))

def _follow_path(self, path, databag, base_path=None):
cwd = os.getcwd()
if base_path:
base_path = os.path.abspath(base_path+ "/" + path)

if os.path.exists(path):
self._load_files(path,databag)
elif base_path and os.path.exists(base_path):
self._load_files(base_path,databag)
else:
self.module.fail_json(msg="Failed to find path '{}'.".format(path), cwd=cwd, base_path=base_path)

def main():
module = AnsibleModule(
Expand Down
2 changes: 1 addition & 1 deletion tasks/debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
owner=root
when: usermanage_debug_level >= 1

- name: debug | Debug Users /tmp/debugUser.{{inventory_hostname}}-{{item.account}}
- name: debug | Debug Users /tmp/debugUser.inventory_hostname-item.account
template:
src=debug_users.j2
dest="{{ usermanage_debug_dir }}/{{ inventory_hostname }}-{{ item.user | default(item.name) }}"
Expand Down
4 changes: 2 additions & 2 deletions tasks/sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
databag: "{{ usermanage_user_source_databag }}"
register: loaded_users_db
connection: local
sudo: no
become: no
when: usermanage_user_source_files is defined and usermanage_user_source_files is not none

- name: sources | Compile effective users
Expand All @@ -19,5 +19,5 @@
source_userdb: "{{ loaded_users_db[usermanage_source_facts] | default(omit) }}"
register: cuser
connection: local
sudo: no
become: no
when: usermanage_usersdb is defined or loaded_users_db[usermanage_source_facts] is defined
4 changes: 2 additions & 2 deletions test/application/advanced.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
- name : Advanced Mode (1)
hosts : "{{ kitchen_hosts }}"
hosts : "all"
gather_facts : no
sudo : True
become : True
connection : "{{ kitchen_connection | default('local') }}"
vars :
usermanage_debug : true
Expand Down
4 changes: 2 additions & 2 deletions test/application/extra_advanced.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
- name : Extra user info advanced Mode (1)
hosts : "{{ kitchen_hosts }}"
hosts : "all"
gather_facts : no
sudo : True
become : True
connection : "{{ kitchen_connection | default('local') }}"
vars :
usermanage_debug : true
Expand Down
4 changes: 2 additions & 2 deletions test/application/extra_simple.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
- name : Extra user info Simple Mode (1)
hosts : "{{ kitchen_hosts }}"
hosts : "all"
gather_facts : no
sudo : True
become : True
connection : "{{ kitchen_connection | default('local') }}"
vars :
usermanage_debug : true
Expand Down
4 changes: 2 additions & 2 deletions test/application/extra_team.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
- name : Extra user info Team Mode (1)
hosts : "{{ kitchen_hosts }}"
hosts : "all"
gather_facts : no
sudo : True
become : True
connection : "{{ kitchen_connection | default('local') }}"
vars :
usermanage_debug : true
Expand Down
4 changes: 2 additions & 2 deletions test/application/group.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
- name : Group (1)
hosts : "{{ kitchen_hosts }}"
hosts : "all"
gather_facts : no
sudo : True
become : True
connection : "{{ kitchen_connection | default('local') }}"
vars_files :
- "group_var_group_db.yml"
Expand Down
4 changes: 3 additions & 1 deletion test/application/multi_source_files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
- name : Multi Sources files
hosts : "{{ kitchen_hosts }}"
gather_facts : no
sudo : True
become : True
connection : "{{ kitchen_connection | default('local') }}"
vars_files :
- "group_var_group_db.yml"
vars :
usermanage_user_source_files:
- path: "./user_source/mutli/yaml/"
base_path: "{{ lookup('pipe', 'pwd') }}"
- path: "./user_source/mutli/databag"
databag: true
base_path: "{{ lookup('pipe', 'pwd') }}"
roles :
- "ansible-usermanage"
4 changes: 2 additions & 2 deletions test/application/simple.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
- name : Simple Mode (1)
hosts : "{{ kitchen_hosts }}"
hosts : "all"
gather_facts : no
sudo : True
become : True
connection : "{{ kitchen_connection | default('local') }}"
vars :
usermanage_debug : true
Expand Down
5 changes: 3 additions & 2 deletions test/application/source_databag.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
---
- name : Sources databag
hosts : "{{ kitchen_hosts }}"
hosts : "all"
gather_facts : no
sudo : True
become : True
connection : "{{ kitchen_connection | default('local') }}"
vars_files :
- "group_var_group_db.yml"
vars :
usermanage_user_source_files :
- path: "./user_source/databag/"
databag: true
base_path: "{{ lookup('pipe', 'pwd') }}"

usermanage_debug : true
usermanage_usersdb:
Expand Down
3 changes: 2 additions & 1 deletion test/application/source_files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
- name : Sources files
hosts : "{{ kitchen_hosts }}"
gather_facts : no
sudo : True
become : True
connection : "{{ kitchen_connection | default('local') }}"
vars :
usermanage_user_source_files:
- path: "./user_source/yaml&json/"
databag: false
base_path: "{{ lookup('pipe', 'pwd') }}"

roles :
- "ansible-usermanage"
4 changes: 2 additions & 2 deletions test/application/team.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
- name : Team (1)
hosts : "{{ kitchen_hosts }}"
hosts : "all"
gather_facts : no
sudo : True
become : True
connection : "{{ kitchen_connection | default('local') }}"
vars:
usermanage_debug : true
Expand Down

0 comments on commit 69d11cb

Please sign in to comment.