ansible_spec 0.1.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a6eaba7458c50a2f92bd8ce3530b2ab86aa77049
4
- data.tar.gz: ef13b0f21260f8c85ce13a170ffb2af381be52e1
3
+ metadata.gz: e07abc240db36cb4184a4e946f019a330bd78716
4
+ data.tar.gz: db7a9f7a615c072f922927aed321e35233e018d0
5
5
  SHA512:
6
- metadata.gz: 7bb98c90e0511d304265e652d9a45da6b49bd3c10cda64fc95e0c36dad399507086b5aef12d0df7ed9bdb6c40a9a146e57a26279a1fb580f2c10e93b202eb2c4
7
- data.tar.gz: 11de186207b955da4bbd73b2fe52ac247884378e5b45d96e0dcf55cbfb4d228e025aedddee64c1688dd9a35e8ab22f02aa77a31c8f7a79be566d44e64edd6662
6
+ metadata.gz: fe5e7d75a375f5dd0bc9aeeecf37f0f2409ee819bb496dcd5e657cd880196b6dbbc80747383ee03447cfdfcb07ab775edf14d2c5ac6ad81142b303700f41aabe
7
+ data.tar.gz: a3b2e12c8ae73ff2aeafd5bb0990def9433bda0031ce3b0b2d4e121dba13f04db119acdcd4830e0dab7190b3a7d619d4b5fc0a58d19479ee70fb984537606d97
@@ -0,0 +1,43 @@
1
+ # v0.2
2
+ - fix #24 Support ENV
3
+
4
+ ```
5
+ Example:
6
+ $ PLAYBOOK=site.yml INVENTORY=hosts rake serverspec:Ansible-Sample-TDD
7
+ ```
8
+
9
+ # v0.1.1
10
+
11
+ fix #22
12
+
13
+
14
+ # v0.1
15
+
16
+ - Support Serverspec v2
17
+ - Simplification Rakefile and Modularization. Because of Improvement of testability.
18
+ - Support InventoryParameters
19
+ - ansible_ssh_port
20
+ - ansible_ssh_user
21
+ - ansible_ssh_host
22
+ - ansible_ssh_private_key_file
23
+ - Support [hostlist expressions](http://docs.ansible.com/intro_inventory.html#hosts-and-groups)
24
+ - Support DynamicInventory
25
+
26
+ This gem created template file until v0.0.1.4,
27
+ But it was modularized on v0.1. Because module is easy to unit-test and Rakefile is simple.
28
+
29
+ If you want old release that can create template, use `gem install ansible_spec -v 0.0.1.4`
30
+ But I can't support(Bug fix, Add feature) old release.
31
+
32
+ ## VersionUp from v0.0.1.4 to v0.1
33
+
34
+ ```
35
+ $ rm Rakefile
36
+ $ rm spec/spec_helper.md
37
+ $ ansiblespec-init
38
+ ```
39
+
40
+ # v0.0.1.3
41
+ - Support `.ansiblespec`
42
+
43
+
data/README.md CHANGED
@@ -6,16 +6,9 @@ This gem is Ansible Config Parser for Serverspec.
6
6
  Serverspec RakeTask uses Ansible Config(InventoryFile and Playbook).
7
7
  Support Run Multi Role and Multi Host of Ansible.
8
8
 
9
- This gem created template file until v0.0.1.4,
10
- But it was modularized on v0.1. Because module is easy to unit-test and Rakefile is simple.
11
-
12
- If you want old release that can create template, use `gem install ansible_spec -v 0.0.1.4`
13
- But I can't support(Bug fix, Add feature) old release.
14
-
15
- ## New feature at v0.1
9
+ # feature
16
10
 
17
11
  - Support Serverspec v2
18
- - Simplification Rakefile and Modularization. Because of Improvement of testability.
19
12
  - Support InventoryParameters
20
13
  - ansible_ssh_port
21
14
  - ansible_ssh_user
@@ -24,7 +17,7 @@ But I can't support(Bug fix, Add feature) old release.
24
17
  - Support [hostlist expressions](http://docs.ansible.com/intro_inventory.html#hosts-and-groups)
25
18
  - Support DynamicInventory
26
19
 
27
- ## Installation
20
+ # Installation
28
21
 
29
22
  install it yourself as:
30
23
 
@@ -32,8 +25,8 @@ install it yourself as:
32
25
  $ gem install ansible_spec
33
26
  ```
34
27
 
35
- ## Usage
36
- ### Create Rakafile & spec/spec_helper.rb
28
+ # Usage
29
+ ## Create Rakafile & spec/spec_helper.rb
37
30
 
38
31
  ```
39
32
  $ ansiblespec-init
@@ -43,18 +36,10 @@ $ ansiblespec-init
43
36
  create .ansiblespec
44
37
  ```
45
38
 
46
- ### VersionUp from v0.0.1.4 to v0.1
47
-
48
- ```
49
- $ rm Rakefile
50
- $ rm spec/spec_helper.md
51
- $ ansiblespec-init
52
- ```
53
-
54
- ### Change .ansiblespec(v0.0.1.3)
55
- If `.ansiblespec` is exist, use variables(playbook and inventory).
56
- So, If you don't use `site.yml` and `hosts`, you change this file.
57
- If `.ansiblespec` not found, use `site.yml` as playbook and `hosts` as inventory.
39
+ ## [option] .ansiblespec
40
+ if `.ansiblespec` is exist, use variables(playbook and inventory).
41
+ so, if you don't use `site.yml` and `hosts`, you change this file.
42
+ if `.ansiblespec` not found, use `site.yml` as playbook and `hosts` as inventory.
58
43
 
59
44
  ```.ansiblespec
60
45
  ---
@@ -63,38 +48,21 @@ If `.ansiblespec` not found, use `site.yml` as playbook and `hosts` as inventory
63
48
  inventory: hosts
64
49
  ```
65
50
 
66
- ### Create Ansible Directory
51
+ ## [option] Environment variable
52
+ You can use Environment variable, when RakeTask command. It listed below.
67
53
 
68
- sample is [here](https://github.com/volanja/ansible-sample-tdd)
54
+ - PLAYBOOK playbook name (e.g. site.yml)
55
+ - INVENTORY inventory file name (e.g. hosts)
56
+ I prioritize ENV more than `.ansiblespec`
69
57
 
70
58
  ```
71
- .
72
- ├── .ansiblespec #Create file (use Serverspec). read above section.
73
- ├── README.md
74
- ├── hosts #use Ansible and Serverspec if .ansiblespec is not exist.
75
- ├── site.yml #use Ansible and Serverspec if .ansiblespec is not exist.
76
- ├── nginx.yml #(comment-out) incluted by site.yml
77
- ├── roles
78
- │   └── nginx
79
- │   ├── handlers
80
- │   │   └── main.yml
81
- │   ├── spec #use Serverspec
82
- │   │   └── nginx_spec.rb
83
- │   ├── tasks
84
- │   │   └── main.yml
85
- │   ├── templates
86
- │   │   └── nginx.repo
87
- │   └── vars
88
- │   └── main.yml
89
- ├── Rakefile #Create file (use Serverspec)
90
- └── spec #Create file (use Serverspec)
91
- └── spec_helper.rb
59
+ Example:
60
+ $ PLAYBOOK=site.yml INVENTORY=hosts rake serverspec:Ansible-Sample-TDD
92
61
  ```
93
62
 
94
- ### Serverspec with Ansible
95
- Serverspec use Ansible file. (Rakefile understand Notation of Ansible.)
63
+ ## Inventory
64
+ Serverspec use Ansible Inventory. (Rakefile understand Notation of Ansible.)
96
65
 
97
- * Inventory file
98
66
  Inventory file can sue this:
99
67
  - InventoryParameters
100
68
  - ansible_ssh_port
@@ -105,6 +73,8 @@ Inventory file can sue this:
105
73
  - Group Children
106
74
  - [DynamicInventory](http://docs.ansible.com/intro_dynamic_inventory.html)
107
75
 
76
+ ### Sample
77
+
108
78
  ```hosts
109
79
  [server]
110
80
  # skip line(comment)
@@ -139,14 +109,43 @@ server
139
109
  databases
140
110
  ```
141
111
 
142
- or DynamicInventory(need execute permission)
112
+ ## DynamicInventory(need execute permission)
143
113
 
144
114
  ```
145
115
  #!/bin/bash
146
116
  echo '{"databases": {"hosts": ["host1.example.com", "host2.example.com"],"vars":{"a": true}}}'
147
117
  ```
148
118
 
149
- * playbook
119
+
120
+ # Sample
121
+ ## Directory
122
+ sample is [here](https://github.com/volanja/ansible-sample-tdd)
123
+
124
+ ```
125
+ .
126
+ ├── .ansiblespec #Create file (use Serverspec). read above section.
127
+ ├── README.md
128
+ ├── hosts #use Ansible and Serverspec if .ansiblespec is not exist.
129
+ ├── site.yml #use Ansible and Serverspec if .ansiblespec is not exist.
130
+ ├── nginx.yml #(comment-out) incluted by site.yml
131
+ ├── roles
132
+ │   └── nginx
133
+ │   ├── handlers
134
+ │   │   └── main.yml
135
+ │   ├── spec #use Serverspec
136
+ │   │   └── nginx_spec.rb
137
+ │   ├── tasks
138
+ │   │   └── main.yml
139
+ │   ├── templates
140
+ │   │   └── nginx.repo
141
+ │   └── vars
142
+ │   └── main.yml
143
+ ├── Rakefile #Create file (use Serverspec)
144
+ └── spec #Create file (use Serverspec)
145
+ └── spec_helper.rb
146
+ ```
147
+
148
+ ## Playbook
150
149
  playbook can use `include`
151
150
 
152
151
  ```site.yml
@@ -162,7 +161,7 @@ playbook can use `include`
162
161
  - nginx
163
162
  ```
164
163
 
165
- ## Run Test(Sample)
164
+ ## Run Test
166
165
 
167
166
  ```
168
167
  $ rake -T
@@ -178,7 +177,7 @@ Finished in 0.34306 seconds
178
177
  11 examples, 0 failures
179
178
  ```
180
179
 
181
- ## Contributing
180
+ # Contributing
182
181
 
183
182
  1. Fork it
184
183
  2. Create your feature branch (`git checkout -b my-new-feature`)
@@ -121,7 +121,10 @@ module AnsibleSpec
121
121
  # return: playbook, inventoryfile
122
122
  def self.load_ansiblespec()
123
123
  f = '.ansiblespec'
124
- if File.exist?(f)
124
+ if ENV["PLAYBOOK"] && ENV["INVENTORY"]
125
+ playbook = ENV["PLAYBOOK"]
126
+ inventoryfile = ENV["INVENTORY"]
127
+ elsif File.exist?(f)
125
128
  y = YAML.load_file(f)
126
129
  playbook = y[0]['playbook']
127
130
  inventoryfile = y[0]['inventory']
@@ -129,6 +132,7 @@ module AnsibleSpec
129
132
  playbook = 'site.yml'
130
133
  inventoryfile = 'hosts'
131
134
  end
135
+
132
136
  if File.exist?(playbook) == false
133
137
  puts 'Error: ' + playbook + ' is not Found. create site.yml or ./.ansiblespec See https://github.com/volanja/ansible_spec'
134
138
  exit 1
@@ -1,3 +1,3 @@
1
1
  module AnsibleSpec
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2"
3
3
  end
@@ -530,7 +530,36 @@ EOF
530
530
  end
531
531
 
532
532
  describe "load_ansiblespecの実行" do
533
- context '正常系' do
533
+ context '正常系(環境変数)' do
534
+ require 'yaml'
535
+ tmp_playbook = 'site_env.yml'
536
+ tmp_hosts = 'hosts_env'
537
+
538
+ before do
539
+ ENV['PLAYBOOK'] = tmp_playbook
540
+ ENV['INVENTORY'] = tmp_hosts
541
+ create_file(tmp_playbook,'')
542
+ create_file(tmp_hosts,'')
543
+ @playbook, @inventoryfile = AnsibleSpec.load_ansiblespec()
544
+ end
545
+
546
+ it "playbook is #{tmp_playbook}" do
547
+ expect(@playbook).to eq tmp_playbook
548
+ end
549
+
550
+ it "inventoryfile is #{tmp_hosts}" do
551
+ expect(@inventoryfile).to eq tmp_hosts
552
+ end
553
+
554
+ after do
555
+ ENV.delete('PLAYBOOK')
556
+ ENV.delete('INVENTORY')
557
+ File.delete(tmp_playbook)
558
+ File.delete(tmp_hosts)
559
+ end
560
+ end
561
+
562
+ context '正常系(.ansiblespec)' do
534
563
  require 'yaml'
535
564
  tmp_ansiblespec = '.ansiblespec'
536
565
  tmp_playbook = 'site.yml'
@@ -544,94 +573,212 @@ describe "load_ansiblespecの実行" do
544
573
  playbook: site.yml
545
574
  inventory: hosts
546
575
  EOF
576
+ create_file(tmp_ansiblespec,content)
577
+ create_file(tmp_playbook,'')
578
+ create_file(tmp_hosts,'')
579
+ @playbook, @inventoryfile = AnsibleSpec.load_ansiblespec()
580
+ end
547
581
 
548
- content_p = <<'EOF'
549
- - name: Ansible-Sample-TDD
550
- hosts: server
551
- user: root
552
- roles:
553
- - nginx
554
- - mariadb
555
- EOF
582
+ it "playbook is #{tmp_playbook}" do
583
+ expect(@playbook).to eq tmp_playbook
584
+ end
556
585
 
557
- content_h = <<'EOF'
558
- [server]
559
- 192.168.0.103
560
- 192.168.0.104
561
- EOF
562
- create_file(tmp_ansiblespec,content)
563
- create_file(tmp_playbook,content_p)
564
- create_file(tmp_hosts,content_h)
586
+ it "inventoryfile is #{tmp_hosts}" do
587
+ expect(@inventoryfile).to eq tmp_hosts
588
+ end
589
+
590
+ after do
591
+ File.delete(tmp_ansiblespec)
592
+ File.delete(tmp_playbook)
593
+ File.delete(tmp_hosts)
594
+ end
595
+ end
596
+
597
+ context '正常系(.ansiblespecと環境変数がある場合、環境変数が優先される)' do
598
+ require 'yaml'
599
+ tmp_ansiblespec = '.ansiblespec'
600
+ tmp_playbook = 'site.yml'
601
+ tmp_hosts = 'hosts'
602
+ env_playbook = 'site_env.yml'
603
+ env_hosts = 'hosts_env'
604
+
605
+ before do
606
+ ENV['PLAYBOOK'] = env_playbook
607
+ ENV['INVENTORY'] = env_hosts
608
+ create_file(tmp_ansiblespec,'')
609
+ create_file(tmp_playbook,'')
610
+ create_file(tmp_hosts,'')
611
+ create_file(env_playbook,'')
612
+ create_file(env_hosts,'')
565
613
  @playbook, @inventoryfile = AnsibleSpec.load_ansiblespec()
566
614
  end
567
615
 
568
- it 'playbook is site.yml' do
569
- expect(@playbook).to eq 'site.yml'
616
+ it "playbook is #{env_playbook}" do
617
+ expect(@playbook).to eq env_playbook
570
618
  end
571
619
 
572
- it 'inventoryfile is hosts' do
573
- expect(@inventoryfile).to eq 'hosts'
620
+ it "inventoryfile is #{env_hosts}" do
621
+ expect(@inventoryfile).to eq env_hosts
574
622
  end
575
623
 
576
624
  after do
625
+ ENV.delete('PLAYBOOK')
626
+ ENV.delete('INVENTORY')
577
627
  File.delete(tmp_ansiblespec)
578
628
  File.delete(tmp_playbook)
579
629
  File.delete(tmp_hosts)
630
+ File.delete(env_playbook)
631
+ File.delete(env_hosts)
580
632
  end
581
633
  end
582
634
 
583
- context '異常系(.ansiblespecがないが、site.ymlとhostsがある場合)' do
635
+ context '正常系(.ansiblespecと環境変数がないが、site.ymlとhostsがある場合)' do
584
636
  require 'yaml'
585
637
  tmp_playbook = 'site.yml'
586
638
  tmp_hosts = 'hosts'
587
639
 
588
640
  before do
641
+ create_file(tmp_playbook,'')
642
+ create_file(tmp_hosts,'')
643
+ @playbook, @inventoryfile = AnsibleSpec.load_ansiblespec()
644
+ end
589
645
 
590
- content_p = <<'EOF'
591
- - name: Ansible-Sample-TDD
592
- hosts: server
593
- user: root
594
- roles:
595
- - nginx
596
- - mariadb
597
- EOF
646
+ it "playbook is #{tmp_playbook}" do
647
+ expect(@playbook).to eq tmp_playbook
648
+ end
598
649
 
599
- content_h = <<'EOF'
600
- [server]
601
- 192.168.0.103
602
- 192.168.0.104
603
- EOF
604
- create_file(tmp_playbook,content_p)
605
- create_file(tmp_hosts,content_h)
650
+ it "inventoryfile is #{tmp_hosts}" do
651
+ expect(@inventoryfile).to eq tmp_hosts
652
+ end
653
+
654
+ after do
655
+ File.delete(tmp_playbook)
656
+ File.delete(tmp_hosts)
657
+ end
658
+ end
659
+
660
+ context '異常系(環境変数PLAYBOOKがないので初期値を使う)' do
661
+ require 'yaml'
662
+ tmp_playbook = 'site.yml'
663
+ tmp_hosts = 'hosts'
664
+ env_hosts = 'hosts_env'
665
+
666
+ before do
667
+ ENV['INVENTORY'] = tmp_hosts
668
+ create_file(tmp_playbook,'')
669
+ create_file(tmp_hosts,'')
606
670
  @playbook, @inventoryfile = AnsibleSpec.load_ansiblespec()
607
671
  end
608
672
 
609
- it 'playbook is site.yml' do
610
- expect(@playbook).to eq 'site.yml'
673
+ it "playbook is #{tmp_playbook}" do
674
+ expect(@playbook).to eq tmp_playbook
611
675
  end
612
676
 
613
- it 'inventoryfile is hosts' do
614
- expect(@inventoryfile).to eq 'hosts'
677
+ it "inventoryfile is #{tmp_hosts}" do
678
+ expect(@inventoryfile).to eq tmp_hosts
615
679
  end
616
680
 
617
681
  after do
682
+ ENV.delete('INVENTORY')
618
683
  File.delete(tmp_playbook)
619
684
  File.delete(tmp_hosts)
620
685
  end
621
686
  end
622
687
 
623
- context '異常系(.ansiblespecとsite.ymlがないが、hostsがある場合)' do
688
+ context '異常系(環境変数INVENTORYがないので初期値を使う)' do
624
689
  require 'yaml'
690
+ tmp_playbook = 'site.yml'
625
691
  tmp_hosts = 'hosts'
692
+ env_playbook = 'site_env.yml'
626
693
 
627
694
  before do
695
+ ENV['PLAYBOOK'] = tmp_playbook
696
+ create_file(tmp_playbook,'')
697
+ create_file(tmp_hosts,'')
698
+ @playbook, @inventoryfile = AnsibleSpec.load_ansiblespec()
699
+ end
628
700
 
629
- content_h = <<'EOF'
630
- [server]
631
- 192.168.0.103
632
- 192.168.0.104
701
+ it "playbook is #{tmp_playbook}" do
702
+ expect(@playbook).to eq tmp_playbook
703
+ end
704
+
705
+ it "inventoryfile is #{tmp_hosts}" do
706
+ expect(@inventoryfile).to eq tmp_hosts
707
+ end
708
+
709
+ after do
710
+ ENV.delete('PLAYBOOK')
711
+ File.delete(tmp_playbook)
712
+ File.delete(tmp_hosts)
713
+ end
714
+ end
715
+
716
+ context '異常系(環境変数INVENTORYがないので.ansiblespecを使う)' do
717
+ require 'yaml'
718
+ tmp_ansiblespec = '.ansiblespec'
719
+ tmp_playbook = 'site_spec.yml'
720
+ tmp_hosts = 'hosts_spec'
721
+ env_playbook = 'site_env.yml'
722
+ env_hosts = 'hosts_env'
723
+
724
+ before do
725
+ ENV['PLAYBOOK'] = env_playbook
726
+ content = <<'EOF'
727
+ ---
728
+ -
729
+ playbook: site_spec.yml
730
+ inventory: hosts_spec
633
731
  EOF
634
- create_file(tmp_hosts,content_h)
732
+ create_file(tmp_ansiblespec,content)
733
+ create_file(tmp_playbook,'')
734
+ create_file(tmp_hosts,'')
735
+ create_file(env_playbook,'')
736
+ create_file(env_hosts,'')
737
+ @playbook, @inventoryfile = AnsibleSpec.load_ansiblespec()
738
+ end
739
+
740
+ it "playbook is #{tmp_playbook}" do
741
+ expect(@playbook).to eq tmp_playbook
742
+ end
743
+
744
+ it "inventoryfile is #{tmp_hosts}" do
745
+ expect(@inventoryfile).to eq tmp_hosts
746
+ end
747
+
748
+ after do
749
+ ENV.delete('PLAYBOOK')
750
+ File.delete(tmp_ansiblespec)
751
+ File.delete(tmp_playbook)
752
+ File.delete(tmp_hosts)
753
+ File.delete(env_playbook)
754
+ File.delete(env_hosts)
755
+ end
756
+ end
757
+
758
+ context '異常系(環境変数で指定したファイルがない場合)' do
759
+ require 'yaml'
760
+
761
+ before do
762
+ ENV['PLAYBOOK'] = 'site_env.yml'
763
+ ENV['INVENTORY'] = 'hosts_env'
764
+ end
765
+
766
+ it 'exitする' do
767
+ expect{ AnsibleSpec.load_ansiblespec }.to raise_error(SystemExit)
768
+ end
769
+
770
+ after do
771
+ ENV.delete('PLAYBOOK')
772
+ ENV.delete('INVENTORY')
773
+ end
774
+ end
775
+
776
+ context '異常系(.ansiblespecとsite.ymlがないが、hostsがある場合)' do
777
+ require 'yaml'
778
+ tmp_hosts = 'hosts'
779
+
780
+ before do
781
+ create_file(tmp_hosts,'')
635
782
  end
636
783
 
637
784
  it 'exitする' do
@@ -648,16 +795,7 @@ EOF
648
795
  tmp_playbook = 'site.yml'
649
796
 
650
797
  before do
651
-
652
- content_p = <<'EOF'
653
- - name: Ansible-Sample-TDD
654
- hosts: server
655
- user: root
656
- roles:
657
- - nginx
658
- - mariadb
659
- EOF
660
- create_file(tmp_playbook,content_p)
798
+ create_file(tmp_playbook,'')
661
799
  end
662
800
 
663
801
  it 'exitする' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ansible_spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - volanja
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-25 00:00:00.000000000 Z
11
+ date: 2015-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -120,6 +120,7 @@ files:
120
120
  - .gitignore
121
121
  - .rspec
122
122
  - .travis.yml
123
+ - CHANGELOG.md
123
124
  - Gemfile
124
125
  - LICENSE.txt
125
126
  - README.md