Good old bash with cloudmonkey...some variables need to be populated
(obviously...)



#!/bin/bash
################################################################################
# Vars / constants
DEPLOYLOG="/tmp/deployzone.log";

################################################################################
# Write to log file + console
function WriteOutput()
{
  local LogTimestamp;
  LogTimestamp=`date +"%Y-%m-%d %H:%M:%S"`;
  echo -e "$*"
  echo ${LogTimestamp} "$*" >> ${DEPLOYLOG};
}

WriteOutput "Checking login.";
AccountCheck=`cloudmonkey list accounts name=admin | grep -i error`;
if [ -z ${AccountCheck} ];
then
  WriteOutput "Admin account found. Good to go.";
else
  WriteOutput "Unable to log in, please check CloudStack installation.";
  exit 1;
fi

WriteOutput "Checking if zone exists."
ZoneCheck=`cloudmonkey list zones`;
if [ -z ${ZoneCheck} ];
then
  WriteOutput "No zone exists. Good to go."
else
  WriteOutput "Zone already present, bailing out."
  exit 1
fi

WriteOutput "Creating advanced zone - {{ bc_zonename }}";
ZoneID=`cloudmonkey create zone networktype=Advanced
securitygroupenabled=false guestcidraddress={{ bc_zone_guestcidr }}
name={{ bc_zonename }} dns1={{ bc_zone_dns1 }} dns2={{ bc_zone_dns2 }}
internaldns1={{ bc_zone_intdns1 }} internaldns2={{ bc_zone_intdns2 }}
localstorageenabled={{ bc_local_storage }} | jq -c -r '.zone.id'`;
WriteOutput "Zone created with ID ${ZoneID}.";
WriteOutput "Creating physical network";
cloudmonkey create physicalnetwork zoneid=${ZoneID} name='{{
bc_zone_physnet }}' isolationmethods='VLAN' | tee -i -a ${DEPLOYLOG};
PhysNetMgmtID=`cloudmonkey list physicalnetworks name="{{
bc_zone_physnet }}" | jq '.physicalnetwork[] | .id'`;
PhysNetPubID=`cloudmonkey list physicalnetworks name="{{
bc_zone_physnet }}" | jq '.physicalnetwork[] | .id'`;
PhysNetGuestID=`cloudmonkey list physicalnetworks name="{{
bc_zone_physnet }}" | jq '.physicalnetwork[] | .id'`;
WriteOutput "Physical network - Management created with ID = ${PhysNetMgmtID}";
WriteOutput "Physical network - Public created with ID = ${PhysNetPubID}";
WriteOutput "Physical network - Guest created with ID = ${PhysNetGuestID}";
WriteOutput "Adding Traffic Type - Public (Advanced Network).";
cloudmonkey add traffictype physicalnetworkid=${PhysNetPubID}
traffictype='Public' xennetworklabel='{{ bc_publiclabel }}' | tee -i
-a ${DEPLOYLOG};
WriteOutput "Adding Traffic Type - Guest (Advanced Network)";
cloudmonkey add traffictype physicalnetworkid=${PhysNetGuestID}
traffictype='Guest' xennetworklabel='{{ bc_guestlabel }}' | tee -i -a
${DEPLOYLOG};
WriteOutput "Adding Traffic Type - Management";
cloudmonkey add traffictype physicalnetworkid=${PhysNetMgmtID}
traffictype='Management' xennetworklabel='{{ bc_mgmtlabel }}' | tee -i
-a ${DEPLOYLOG};
PhysNetArray=`cloudmonkey list physicalnetworks filter=id | jq
'.physicalnetwork[] | .id'`;
for i in ${PhysNetArray};
do
  WriteOutput "Enabling Physical Network ${i}";
  cloudmonkey update physicalnetwork state='Enabled' id=${i}  | tee -i
-a ${DEPLOYLOG};
done
NetProvArrayAdv=`cloudmonkey list networkserviceproviders
filter=name,id | jq '.networkserviceprovider[] |
select(.name!="SecurityGroupProvider") | .id' | tr " " "\n"`;
IntLBArrayAdv=`cloudmonkey list internalloadbalancerelements
filter=name,id | jq '.internalloadbalancerelement[] | .id' | tr " "
"\n"`;
VRArrayAdv=`cloudmonkey list virtualrouterelements filter=name,id | jq
'.virtualrouterelement[] | .id' | tr " " "\n"`;
for i in ${IntLBArrayAdv};
do
  WriteOutput "Enabling internalloadbalancerelements ${i}";
  cloudmonkey configure internalloadbalancerelement enabled='true'
id=${i} | tee -i -a ${DEPLOYLOG};
done
for i in ${VRArrayAdv};
do
  WriteOutput "Enabling virtualrouterelement ${i}";
  cloudmonkey configure virtualrouterelement enabled='true' id=${i} |
tee -i -a ${DEPLOYLOG};
done
for i in ${NetProvArrayAdv};
do
  WriteOutput "Enabling networkserviceprovider ${i}";
  cloudmonkey update networkserviceprovider state='Enabled' id=${i} |
tee -i -a ${DEPLOYLOG};
done

WriteOutput "Creating public range.";
cloudmonkey create vlaniprange zoneid=${ZoneID} vlan="{{ bc_pubvlan
}}" gateway="{{ bc_pubgw }}" netmask="{{ bc_pubmask }}" startip="{{
bc_pubstartip }}" endip="{{ bc_pubendip }}" forvirtualnetwork="true" |
tee -i -a ${DEPLOYLOG};
WriteOutput "Creating Guest VLAN range."
cloudmonkey update physicalnetwork id=${PhysNetGuestID} vlan="{{
bc_podvlans }}" | tee -i -a ${DEPLOYLOG};

WriteOutput "Creating 1st Pod.";
cloudmonkey create pod zoneid=${ZoneID} name="{{ bc_zone_podname }}"
gateway="{{ bc_podgw }}" netmask="{{ bc_podmask }}" startip="{{
bc_podstartip }}" endip="{{ bc_podendip }}" | tee -i -a ${DEPLOYLOG};
PodID=`cloudmonkey list pods name={{ bc_zone_podname }} filter=id | jq
'.pod[] | .id'`;
WriteOutput "First Pod created with ID = ${PodID}";

WriteOutput "Adding XenServer cluster.";
ClusterID_XS=`cloudmonkey add cluster zoneid=${ZoneID}
hypervisor='XenServer' clustertype='CloudManaged' podid=${PodID}
clustername="{{ bc_clustername }}"  | jq '.cluster[] | .id'`;
WriteOutput "Adding XenServer hosts.";
cloudmonkey add host zoneid=${ZoneID} podid=${PodID}
clusterid=${ClusterID_XS} hypervisor=XenServer password="{{ bc_rootpwd
}}" username="{{ bc_rootuser }}" url="http://{{ bc_xsmgmtip }}" | tee
-i -a ${DEPLOYLOG};
sleep 30

WriteOutput "Adding Primary Storage pool.";
cloudmonkey create storagepool zoneid=${ZoneID} podid=${PodID}
clusterid=${ClusterID_XS} name='{{ bc_pripool }}' scope='cluster'
url="NFS://{{ bc_mgmtip }}{{ bc_pripath }}" | tee -i -a ${DEPLOYLOG};

WriteOutput "Adding Secondary Storage Pool"
cloudmonkey add imagestore name='{{ bc_secpool }}' provider='NFS'
zoneid=${ZoneID} url="NFS://{{ bc_mgmtip }}{{ bc_secpath }}" | tee -i
-a ${DEPLOYLOG};

WriteOutput "Enabling zone."
cloudmonkey update zone allocationstate='Enabled' id=${ZoneID} | tee
-i -a ${DEPLOYLOG};
WriteOutput "You're done. Good luck!";


On Tue, 29 Jun 2021 at 08:09, Rohit Yadav <rohit.ya...@shapeblue.com> wrote:

> Hi,
>
> Here are some docs you can refer to:
>
> https://docs.cloudstack.apache.org/en/latest/developersguide/ansible.html
>
> https://docs.ansible.com/ansible/latest/scenario_guides/guide_cloudstack.html
>
> https://github.com/shapeblue/hackerbook/blob/main/hack/automation.md#ansible-and-cloudstack
>
> Hope this helps.
>
> Regards,
> Rohit Yadav
>
> ________________________________
> From: Rafael del Valle <rva...@privaz.io.INVALID>
> Sent: Monday, June 28, 2021 12:55:11 PM
> To: users@cloudstack.apache.org <users@cloudstack.apache.org>
> Cc: users@cloudstack.apache.org <users@cloudstack.apache.org>
> Subject: Re: How to use ansible for cloudstack initialization
>
> Hi Rudraksh,
> Interesting.
>
> it may also be possible to turn your python scripting to read the files
> that customers provide into an alternative lookup plugin if CSV doesn't fit
> well.
>
> Regards,
> Rafael
>
>
> On Mon, 2021-06-28 07:50 AM, Rudraksh MK <rudra...@indiqus.com.INVALID>
> wrote:
> > Hi Rene!
> >
> > My apologies, I ought to have been a little clearer. Your playbooks are
> just perfect, when it comes to configuring an ACS deployment with zones and
> clusters and pods and so on. In our use case though, what typically happens
> is that a service provider usually provides spreadsheets with details about
> the zones and all they want. While Ansible has the capability when it comes
> to reading CSVs, it felt more verbose to write playbooks to do that;
> scripting it in Python felt easier.
> >
> > Having said that, I think I’d like to take a shot at this again, and see
> if we can use spreadsheets containing config details with your collection.
> >
> > Oh and thank you for your work on this :)
> >
> >
> > Best!
> >
> > Rudraksh Mukta Kulshreshtha
> > Vice-President - DevOps & R&D
> > IndiQus Technologies
> > O +91 11 4055 1411 | M +91 99589 54879
> > indiqus.com
> >
> > This message is intended only for the use of the individual or entity to
> which it is addressed and may contain information that is confidential
> and/or privileged. If you are not the intended recipient please delete the
> original message and any copy of it from your computer system. You are
> hereby notified that any dissemination, distribution or copying of this
> communication is strictly prohibited unless proper authorization has been
> obtained for such action. If you have received this communication in error,
> please notify the sender immediately. Although IndiQus attempts to sweep
> e-mail and attachments for viruses, it does not guarantee that both are
> virus-free and accepts no liability for any damage sustained as a result of
> viruses.
> > On 27 Jun 2021, 7:17 PM +0530, Rene Moser " target="_blank"><
> m...@renemoser.net>, wrote:
> > > Hi Jerry
> > >
> > > I am one of the authors of the cloudstack ansible integration, you can
> > > find the docs about every ansible module here
> > >
> https://docs.ansible.com/ansible/latest/collections/ngine_io/cloudstack/index.html
> > >
> > > We have intregration tests playbooks, which also creates zones, pods,
> > > cluster, etc., which you can find here
> > >
> https://github.com/ngine-io/ansible-collection-cloudstack/tree/master/tests/integration/targets
> > >
> > > further, Rafael (in cc) showed on the last cloudstack europe meetup how
> > > they provisioned cloudstack using ansible. You may get in touch with.
> > >
> > > And I can not confirm that "Ansible felt slightly..clunky in this
> > > context." We made it as easy and reliable as possible to use ansible
> > > with cloudstack and continue to do so, if you feel, something is
> > > missing, feel free to get in touch.
> > >
> > > On 26.06.21 10:34, li jerry wrote:
> > > > Hello everyone
> > > >
> > > > Does anyone use ansible to add zone/pod/cluster/host/storage to
> cloudstack?
> > >
> > >
> > > > Currently I can only use ansible to complete the deployment of
> cloudstack, nfs, mysql and other services.
> > > > I can't use ansible to complete operations such as adding zone/pod
> > > >
> > > > Can someone provide relevant documents or solutions?
> > >
> > >
> >
>
>
>
>

-- 

Andrija Panić

Reply via email to