I've been struggling to get a group modification (via 'lgroupmod') for the user packer is using to login to an AWS instance to take effect for later provisioning. I've made the group mod in one shell provisioner and expected it to take effect in later shell provisioners, because I thought each unique shell block would initiate a new ssh and login, thus making the change take effect.
Here's the simplified JSON test case:
{
"builders": [{
"type": "amazon-ebs",
"access_key": "{{user `aws_access_key`}}",
"secret_key": "{{user `aws_secret_key`}}",
"region": "{{user `aws_region`}}",
"source_ami": "{{user `aws_source_ami`}}",
"instance_type": "{{user `aws_instance_type`}}",
"ssh_username": "{{user `aws_ssh_username`}}",
"ssh_keypair_name": "{{user `aws_deploy_key`}}",
"ssh_private_key_file": "{{user `ssh_key_file`}}",
"ami_name": "{{user `aws_ami_name`}}",
"subnet_id": "{{user `aws_subnet_id`}}",
"vpc_id": "{{user `aws_vpc_id`}}",
"security_group_id": "{{user `aws_security_group`}}",
"ssh_pty": "true",
"launch_block_device_mappings": [{
"device_name": "/dev/sda1",
"volume_size": "100",
"delete_on_termination": "true"
}]
}],
"provisioners": [
{
"type": "shell",
"inline": [
"sudo groupadd testgroup 2>&1 | tee -a /tmp/tg.out",
"sudo lgroupmod -M centos testgroup 2>&1 | tee -a /tmp/tg.out"
]
},
{
"type": "shell",
"inline_shebang": "/usr/bin/bash -lex",
"inline": [
"grep testgroup /etc/group 2>&1 | tee -a /tmp/tg.out",
"groups 2>&1 | tee -a /tmp/tg.out"
]
}
]
}
The output in /tmp/tg.out of running the above (which is all from the second shell) is:
[centos@ip-10-100-26-228 ~]$ cat /tmp/tg.out
testgroup:x:1001:centos
centos adm wheel systemd-journal
As shown, the key problem here is the centos user, which is used by packer to login to the instance, never has its group membership in 'testgroup' established for the life of the packer builder.
I've tried putting the second shell calls in other scripts with '#!/usr/bin/bash -l' to invoke a login shell, I've tried doing it with the provisioner's shebang argument as above, but nothing seems to actually cause a new/fresh ssh login that would show the group membership.
I have full output captured if it's useful but at this point maybe it's not needed if I'm missing something essential or perhaps this isn't possible with packer?
I've looked at related conversations without seeing a clear answer:
https://groups.google.com/forum/#!searchin/packer-tool/login/packer-tool/tbETccmKk-A/Vj06LvOpbnsJhttps://groups.google.com/forum/#!topic/packer-tool/hWKdjEj4izoThanks in advance,
Brett