有条件地设置Ansible角色默认值

时间:2016-10-17 09:21:36

标签: ansible ansible-role

伪代码:

如果env是de,如果env是prod,则将变量名设置为hello else,将变量名设置为bye。

我尝试了https://serverfault.com/questions/715769/ansible-change-default-value-according-to-a-condition

 public List<string[]> GetRunningOrderOnTable(string tableNo, int shopid)
        {
            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                string xmlFilePath = @"C:\inetpub\wwwroot\ShopAPI\XmlData\RunningTables.xml";
                //string xmlFilePath = HttpContext.Current.Server.MapPath("~/XmlData/RunningTables.xml");
      // Option 1
                //                FileStream xmlFile = new FileStream(xmlFilePath, FileMode.Open,
                //FileAccess.Read, FileShare.Read);
                //                xmlDoc.Load(xmlFile);
      // Option 2
                using (Stream s = File.OpenRead(xmlFilePath))
                {
                    xmlDoc.Load(s);
                }
                //xmlDoc.Load(xmlFilePath);
                List<string[]> st = new List<string[]>();
                XmlNodeList userNodes = xmlDoc.SelectNodes("//Tables/Table");
                if (userNodes != null)
                {
                    foreach (XmlNode userNode in userNodes)
                    {
                        string tblNo = userNode.Attributes["No"].Value;
                        string sid = userNode.Attributes["ShopID"].Value;
                        if (tblNo == tableNo && sid == shopid.ToString())
                        {
                            string[] str = new string[5];
                            str[0] = userNode.Attributes["No"].Value;
                            str[1] = userNode.InnerText; // OrderNumber
                            str[2] = userNode.Attributes["OrderID"].Value;
                            str[3] = userNode.Attributes["OrderedOn"].Value;
                            str[4] = userNode.Attributes["TotalAmount"].Value;
                            st.Add(str);
                        }
                    }
                }
                else return new List<string[]>();
                return st;
            }
            catch (Exception ex)
            {

                CustomLogging.Log("RunningTables.xml GetRunningOrderOnTable Error " + ex.StackTrace, LoggingType.XMLRead);
                return new List<string[]>();
            }
        }
  

ERROR!角色&#39;试用&#39;的默认/ main.yml文件必须包含一个   变量字典

1 个答案:

答案 0 :(得分:0)

根据我的要求,它需要在角色中完成。所以它按如下方式完成:

名称:“{%if env =='de'%} hello {%elif env =='prod'%} bye {%endif%}”

相关问题