10
10
let ( :env_vars ) { { } }
11
11
let ( :extra_vars ) { { } }
12
12
13
- def expect_ansible_runner_success ( response )
14
- expect ( response . return_code ) . to eq ( 0 ) , "ansible-runner failed with:\n ====== STDERR ======\n #{ response . stderr } \n \n ====== STDOUT ======\n #{ response . human_stdout } "
15
- end
16
-
17
13
it "runs a playbook" do
18
14
playbook = data_directory . join ( "hello_world.yml" )
19
15
@@ -56,18 +52,18 @@ def expect_ansible_runner_success(response)
56
52
expect ( response . human_stdout ) . to include ( '"msg": "Hello World! vars_file_1=vars_file_1_value, vars_file_2=vars_file_2_value"' )
57
53
end
58
54
59
- context "runs a playbook using roles from github " do
60
- let ( :roles_dir ) { data_directory . join ( "hello_world_with_requirements_github/roles/manageiq.example" ) }
55
+ context "with a roles/requirements.yml " do
56
+ let ( :roles_path ) { data_directory . join ( "hello_world_with_requirements_github/roles/manageiq.example" ) }
61
57
62
- after { FileUtils . rm_rf ( roles_dir ) }
58
+ after { FileUtils . rm_rf ( roles_path ) }
63
59
64
- it do
60
+ it "runs a playbook using roles from github" do
65
61
playbook = data_directory . join ( "hello_world_with_requirements_github/hello_world_with_requirements_github.yml" )
66
62
67
63
response = Ansible ::Runner . public_send ( method_under_test , env_vars , extra_vars , playbook )
68
64
response = response . wait ( 5 . seconds ) if async
69
65
70
- expect ( roles_dir ) . to exist
66
+ expect ( roles_path ) . to exist
71
67
expect_ansible_runner_success ( response )
72
68
expect ( response . human_stdout ) . to include ( '"msg": "Hello World! example_var=\'example var value\'"' )
73
69
end
@@ -82,6 +78,29 @@ def expect_ansible_runner_success(response)
82
78
end
83
79
end
84
80
81
+ shared_examples_for :executing_roles do
82
+ let ( :method_under_test ) { async ? :run_role_async : :run_role }
83
+ let ( :env_vars ) { { } }
84
+ let ( :extra_vars ) { { } }
85
+
86
+ let ( :roles_path ) { Dir . mktmpdir ( "ansible-runner-roles-test" ) }
87
+
88
+ before do
89
+ FileUtils . cp ( data_directory . join ( "hello_world_with_requirements_github/roles/requirements.yml" ) , roles_path )
90
+ AwesomeSpawn . run! ( "ansible-galaxy" , :params => [ "install" , { :role_file => "requirements.yml" , :roles_path => "." } ] , :chdir => roles_path )
91
+ end
92
+
93
+ after { FileUtils . rm_rf ( roles_path ) }
94
+
95
+ it "runs a role" do
96
+ response = Ansible ::Runner . public_send ( method_under_test , env_vars , extra_vars , "manageiq.example" , roles_path : roles_path )
97
+ response = response . wait ( 5 . seconds ) if async
98
+
99
+ expect_ansible_runner_success ( response )
100
+ expect ( response . human_stdout ) . to include ( %q{"msg": "Hello from manageiq.example role! example_var='example var value'"} )
101
+ end
102
+ end
103
+
85
104
describe ".run" do
86
105
let ( :async ) { false }
87
106
include_examples :executing_playbooks
@@ -91,4 +110,18 @@ def expect_ansible_runner_success(response)
91
110
let ( :async ) { true }
92
111
include_examples :executing_playbooks
93
112
end
113
+
114
+ describe ".run_role" do
115
+ let ( :async ) { false }
116
+ include_examples :executing_roles
117
+ end
118
+
119
+ describe ".run_role_async" do
120
+ let ( :async ) { true }
121
+ include_examples :executing_roles
122
+ end
123
+
124
+ def expect_ansible_runner_success ( response )
125
+ expect ( response . return_code ) . to eq ( 0 ) , "ansible-runner failed with:\n ====== STDERR ======\n #{ response . stderr } \n \n ====== STDOUT ======\n #{ response . human_stdout } "
126
+ end
94
127
end
0 commit comments