Skip to content

Commit

Permalink
Use repo for ansible installation
Browse files Browse the repository at this point in the history
Signed-off-by: CS Zhang <zhangcho@us.ibm.com>
  • Loading branch information
cs-zhang committed Jan 29, 2021
1 parent 59d11d3 commit 44fd758
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
30 changes: 28 additions & 2 deletions modules/1_bastion/bastion.tf
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,34 @@ EOF
}
}

resource "null_resource" "enable_repos" {
count = ( var.rhel_subscription_username == "" || var.rhel_subscription_username == "<subscription-id>" ) && var.rhel_subscription_org == "" ? 0 : 1
depends_on = [null_resource.bastion_init, null_resource.setup_proxy_info, null_resource.bastion_register]

connection {
type = "ssh"
user = var.rhel_username
host = openstack_compute_instance_v2.bastion.access_ip_v4
private_key = var.private_key
agent = var.ssh_agent
timeout = "${var.connection_timeout}m"
}

provisioner "remote-exec" {
inline = [<<EOF
# Additional repo for installing ansible package
if ( [[ -z "${var.rhel_subscription_username}" ]] || [[ "${var.rhel_subscription_username}" == "<subscription-id>" ]] ) && [[ -z "${var.rhel_subscription_org}" ]]; then
sudo yum install -y epel-release
else
sudo subscription-manager repos --enable ${var.ansible_repo_name}
fi
EOF
]
}
}

resource "null_resource" "bastion_packages" {
depends_on = [null_resource.bastion_init, null_resource.setup_proxy_info, null_resource.bastion_register]
depends_on = [null_resource.bastion_init, null_resource.setup_proxy_info, null_resource.bastion_register, null_resource.enable_repos]
connection {
type = "ssh"
user = var.rhel_username
Expand All @@ -237,7 +263,7 @@ resource "null_resource" "bastion_packages" {
}
provisioner "remote-exec" {
inline = [
"pip3 install ansible -q"
"sudo yum install -y ansible"
]
}
provisioner "remote-exec" {
Expand Down
1 change: 1 addition & 0 deletions modules/1_bastion/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ variable "rhel_subscription_username" {}
variable "rhel_subscription_password" {}
variable "rhel_subscription_org" {}
variable "rhel_subscription_activationkey" {}
variable "ansible_repo_name" {}

variable "storage_type" {}
variable "volume_size" {}
Expand Down
1 change: 1 addition & 0 deletions ocp.tf
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ module "bastion" {
rhel_subscription_password = var.rhel_subscription_password
rhel_subscription_org = var.rhel_subscription_org
rhel_subscription_activationkey = var.rhel_subscription_activationkey
ansible_repo_name = var.ansible_repo_name
storage_type = var.storage_type
volume_size = var.volume_size
volume_storage_template = var.volume_storage_template
Expand Down
1 change: 1 addition & 0 deletions var.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ cluster_id = ""

#installer_log_level = "info"
#ansible_extra_options = "-v"
#ansible_repo_name = "ansible-2.9-for-rhel-8-ppc64le-rpms"
#dns_forwarders = "1.1.1.1; 9.9.9.9"
#rhcos_kernel_options = []
#chrony_config = true
Expand Down
4 changes: 4 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ variable "ansible_extra_options" {
default = "-v"
}

variable "ansible_repo_name" {
default = "ansible-2.9-for-rhel-8-ppc64le-rpms"
}

locals {
private_key_file = var.private_key_file == "" ? "${path.cwd}/data/id_rsa" : var.private_key_file
public_key_file = var.public_key_file == "" ? "${path.cwd}/data/id_rsa.pub" : var.public_key_file
Expand Down

0 comments on commit 44fd758

Please sign in to comment.