Commit ac4c713b authored by Swann Perarnau's avatar Swann Perarnau

[feature] add playbook arg to configure

Usefull for users that want to try a different set of roles.
parent c3308df5
......@@ -144,6 +144,8 @@ 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'
......@@ -162,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'
......@@ -170,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-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:
......@@ -247,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()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment