Welcome to the 1st Imperial Church of Awesome
In the Warhammer 40K universe, a Chaplain is a basically a Space Marine version of the Ecclesiastical priest, but with guns and power armor.
Chaplains were originally formed by Lorgar as part of the religious slant he brought to the Word Bearers, charging them with spreading the cult of the Lectitio Divinatus, his early form of Emperor-worship. After assuming control of the Council of Terra, Malcador the Sigillite instructed the Space Marine Legions to employ Chaplains to enforce the Decree of Nikea, the Emperor's restrictions on Librarians, as a sort of proto-Commissar.
In the present, a Chaplain's role in a chapter is to root out heresy, inspire other Marines by chanting a litany of verses, maintain the Chapter's relics and traditions, and basically make the Marines around him righteously angry. Unlike Commissars of the Imperial Guard, he isn't keen on executing his own men for simple cowardice, mainly because Space Marines only retreat to gain a better tactical advantage and the fact that a Marine is more expensive to create than an expendable guardsman; but he does still torture/kill xenos, mutants and heretics for tactical, religious, or recreational purposes. Chaplains are an HQ unit and use a Crozius Arcanum. It is their badge of office/fuckhueg mace capable of ignoring armor and utterly shattering your head right off of your shoulders in a single swipe, while looking totally sweet in his black power armour and skull visage helmet, while scaring the living shit out of the enemy. Higher ranked Chaplains may instead take artificer or Terminator armor. Outside of the company Chaplains, you have the Master of Sanctity or High Chaplain, who oversees the Chapter Chaplaincy and is a senior advisor to the Chapter Master, and the Reclusiarch, who oversees the Reclusiam, where the Chapter's sacred relics and trophies are displayed. Often times the two posts are combined.
For all intents and purposes, just imagine a Space Marine, but even more fanatical and badass. He also has great oratorical skills to make his brothers stop bitching and to pick up his knife then charge that Bloodthirster and stab him right in the balls because godsdamnit that's how you make the Emprah proud. It is also suggested that Chaplains use their "oratory" skills for other purposes as well, but these may just be rumours spread to question the MANLINESS of the Spess Mehreens.
 Blood Angels Chaplain
The Blood Angels Chaplains were originally known as "Wardens", who served as advisors and mentors to the younger generations. When the Edict of Nikaea was declared and the Chaplain Edict followed, the Wardens were appointed to oversee enforcement. Following the Horus Heresy, the Wardens of the Blood Angels and their successor Chapters became Chaplains, and were tasked with an additional, somber purpose: they were to lead the Death Company, those Marines who fell to the Black Rage and the Red Thirst, into battle. Being surrounded by raging berserkers, the Chaplains must have iron strong wills to oversee these Marines and maintain their own sanity.
 Dark Angels Interrogator-Chaplain
The Dark Angels and their successors have an extra rank for Chaplains who make it into the Inner Circle and learn the "truth" (or at least part of it) about the Fallen Angels. After passing several trials of the soul (the penalty for failure being death or worse), they interrogate (read: torture) captured Fallen Angels to try and force them to repent for their crimes. These "Interrogator-Chaplains" are extremely patient and resilient against the *cough* insidious lies of captured heretics, and will take as long as necessary to finally break them. To put this in perspective, the very best Interrogator-Chaplain that the Dark Angels ever had only managed to get ten Fallen to confess and repent over the course of 300 years of service.
 Iron Hands Iron Father
Among the Iron Hands, the Chaplains are known as an "Iron Father", which combines the role of Chaplain and Techmarine together, which reflects the Iron Hands heavy
obsession preference for augmentics. Also unique in the fact that they're completely separated from the Ecclesiarchy altogether, considering the chapter's predilection towards machinery and the like. The spat ended with them splitting off and the Iron Hands unable to have Rosarii. To compensate that, the Iron Hands have to fabricate their own equivalents using some special Adeptus Mechanicus schemes. Needless to say, when comparing the technological prowess of the Ecchlesiarchy and the Mechanicus...
 Space Wolves Wolf Priest
The Chaplains of the Space Wolves are the Wolf Priests, who combine the role of Chaplain and Apothecary into one. All Wolf Priests, along with the Rune Priests (Librarians) and Iron Priests (Techmarines) serve as part of the Company of the Great Wolf (the elite Great Company under the Chapter Master of the Space Wolves) and are assigned to the other eleven Great Companies as needed.
 Notable Chaplains
PRAISE THE EMPEROR AND PASS THE AMMUNITION!
A Chaplain's role is not only to fight in combat, but to also duel in guitar solos.