Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
argo
infrastructure
Commits
f8865ee4
Commit
f8865ee4
authored
Jun 12, 2018
by
Swann Perarnau
Browse files
Merge branch 'ansible-improvements' into 'master'
Ansible improvements See merge request
!2
parents
440db486
e866ec78
Changes
3
Hide whitespace changes
Inline
Side-by-side
ansible/main.yaml
View file @
f8865ee4
---
-
hosts
:
all
tasks
:
-
name
:
update etc/hosts
lineinfile
:
dest
:
/etc/hosts
line
:
"
{{
hostvars[item].ansible_host
}}
{{
hostvars[item].inventory_hostname
}}
{{
hostvars[item].inventory_hostname_short
}}"
state
:
present
with_items
:
"
{{
groups.all
}}"
become
:
yes
roles
:
-
common
ansible/roles/common/tasks/main.yaml
0 → 100644
View file @
f8865ee4
-
name
:
update etc/hosts
lineinfile
:
dest
:
/etc/hosts
line
:
"
{{
hostvars[item].ansible_host
}}
{{
hostvars[item].inventory_hostname
}}
{{
hostvars[item].inventory_hostname_short
}}"
state
:
present
with_items
:
"
{{
groups.all
}}"
become
:
yes
chi-appliance.py
View file @
f8865ee4
...
...
@@ -51,7 +51,7 @@ def do_create(argv):
template
=
os
.
path
.
abspath
(
argv
.
template
)
try
:
ret
=
shade_client
.
create_stack
(
argv
.
name
,
template_file
=
template
,
wait
=
True
,
**
extra_args
)
wait
=
argv
.
wait
,
**
extra_args
)
print
(
json
.
dumps
(
ret
,
indent
=
4
))
except
shade
.
exc
.
OpenStackCloudHTTPError
as
e
:
print
(
e
)
...
...
@@ -60,7 +60,7 @@ def do_create(argv):
def
do_delete
(
argv
):
"""Delete an appliance with <name>."""
shade_client
=
get_shade_client
(
argv
.
region
)
ret
=
shade_client
.
delete_stack
(
argv
.
name
)
ret
=
shade_client
.
delete_stack
(
argv
.
name
,
wait
=
argv
.
wait
)
if
ret
:
print
(
"Appliance successfully deleted."
)
else
:
...
...
@@ -144,9 +144,16 @@ def do_configure(argv):
# local playbook
mypath
=
os
.
path
.
abspath
(
os
.
path
.
dirname
(
__file__
))
confpath
=
os
.
path
.
join
(
mypath
,
'ansible'
)
# remove potential ./ansible/ from playbook path
playpath
=
os
.
path
.
split
(
argv
.
playbook
)[
1
]
playbook
=
(
'---
\n
'
'- hosts: all
\n
'
' gather_facts: no
\n
'
' tasks:
\n
'
' - name: Wait for frontend
\n
'
' wait_for_connection:
\n
'
' - name: Gather info about frontend
\n
'
' setup:
\n
'
' - name: Ensure dependencies are installed
\n
'
' package:
\n
'
' name: "{{ item }}"
\n
'
...
...
@@ -157,7 +164,7 @@ def do_configure(argv):
' become: yes
\n
'
' - name: Copy ansible configuration to the frontend
\n
'
' synchronize:
\n
'
' src: '
+
confpath
+
'
\n
'
' src: '
+
confpath
+
'
\n
'
' dest: ~/
\n
'
' - name: Generate ssh-key for appliance
\n
'
' user:
\n
'
...
...
@@ -165,14 +172,14 @@ def do_configure(argv):
' state: present
\n
'
' generate_ssh_key: yes
\n
'
' - name: Execute ansible on frontend
\n
'
' command: ansible-playbook -i inventory main.yaml
\n
'
' shell: ANSIBLE_HOST_KEY_CHECKING=False'
' ansible-playbook -i inventory.yaml '
+
playpath
+
'
\n
'
' args:
\n
'
' chdir: ~/ansible
\n
'
' register: config
\n
'
' - debug: var=config.stdout_lines'
)
# generate files
# BAD ERROR HANDLING HERE
remote_inv_path
=
"./ansible/inventory.yaml"
remote_inv_path
=
os
.
path
.
join
(
confpath
,
"inventory.yaml"
)
local_temp
=
NamedTemporaryFile
(
mode
=
'w+'
,
encoding
=
'utf8'
,
delete
=
False
)
play_temp
=
NamedTemporaryFile
(
mode
=
'w+'
,
encoding
=
'utf8'
,
delete
=
False
)
with
open
(
remote_inv_path
,
"w+"
,
encoding
=
'utf8'
)
as
remote_inv
:
...
...
@@ -190,7 +197,7 @@ def do_configure(argv):
universal_newlines
=
True
)
while
True
:
err
=
proc
.
poll
()
if
not
err
:
if
err
is
None
:
print
(
proc
.
stdout
.
readline
(),
end
=
''
,
flush
=
True
)
else
:
if
err
==
0
:
...
...
@@ -216,6 +223,8 @@ def main():
# create a lease
parser_create
=
subparsers
.
add_parser
(
"create"
,
help
=
"Create an appliance"
)
parser_create
.
add_argument
(
"--wait"
,
action
=
'store_true'
,
help
=
"Wait for the operation to complete"
)
parser_create
.
add_argument
(
"name"
,
help
=
"Name of the appliance"
)
parser_create
.
add_argument
(
"lease"
,
help
=
"Lease for the appliance"
)
parser_create
.
add_argument
(
"template"
,
help
=
"Appliance template"
)
...
...
@@ -225,6 +234,8 @@ def main():
parser_create
.
set_defaults
(
func
=
do_create
)
parser_delete
=
subparsers
.
add_parser
(
"delete"
,
help
=
"Delete an appliance"
)
parser_delete
.
add_argument
(
"--wait"
,
action
=
'store_true'
,
help
=
"Wait for the operation to complete"
)
parser_delete
.
add_argument
(
"name"
,
help
=
"Name of the appliance"
)
parser_delete
.
set_defaults
(
func
=
do_delete
)
...
...
@@ -238,6 +249,8 @@ def main():
parser_config
=
subparsers
.
add_parser
(
"configure"
,
help
=
"Configure an appliance"
)
parser_config
.
add_argument
(
"name"
,
help
=
"Name of the appliance"
)
parser_config
.
add_argument
(
"playbook"
,
default
=
"main.yaml"
,
nargs
=
'?'
,
help
=
"Playbook for remote configuration"
)
parser_config
.
set_defaults
(
func
=
do_configure
)
args
=
parser
.
parse_args
()
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment