Local police said 15 of the those killed were Iranians and three were Iraqis, according to numerous reports.
Five Iranians and two Iraqis were also injured.
Machine-gun toting assailants emerged from three vehicles at a site where workers were laying foundation for a pipeline that will carry gas from Iraq to Iran, Al-Jazeera reported.
The attack occurred in a predominantly Sunni area outside the city of Baquba, north-east of Baghdad, according to the BBC.
The attack comes amid increasing violence and instability in Iraq, two years after US troops left the war-ravaged oil producer.
It is the worst violence seen in Iraq since 2008.
After “a particularly bloody November” where between 650 and 950 people lost their lives, London-based security analyst AKE raised its risk assessment in Iraq to 41 out of 100, indicating a “highly dangerous business environment”.
In November, oil services giants Baker Hughes and Schlumberger were forced to suspend operations in Iraq’s Basra region amid angry protests.
Continued violence is fanning fears that the Opec member is teetering on the edge of full-scale conflict.
In a separate attack south of Baghdad on Friday, a car bomb exploded, killing at least six people and wounding at least 13, AFP said. Another car bomb near a fish market in Nahrawan killed four people and wounded at least 12, the news wire reported.
Two others, including a government employee, were killed in a drive-by shooting in Baghdad’s Ghazaliyah area, according to Al-Jazeera.
AFP said as many people were killed in Iraq during the first eight days of this month than in all of December last year.