William Whyte, 39, was at his house at Moorelands, Addiewell, in West Lothian, when police arrived. He was asked if there were drugs in the house and revealed that there was cocaine in a bedroom.
Officers seized half a kilo of the drug worth about £17,000 along with 14 kilos of benzocaine, commonly used to cut the Class A drug.
Defence solicitor advocate Ewen Roy said Whyte had become involved in the offence of holding the drugs for another individual to try to help clear a debt. Mr Roy said Whyte had served with the Royal Scots in Northern Ireland and the first Gulf War.
Whyte earlier admitted being concerned in the supply of the Class A drug on May 16 and 17 this year.