chore(pulumi): send commands from pulumi up

This commit is contained in:
Michele Cereda
2024-07-22 23:19:29 +02:00
parent ca8a9eaec1
commit 96e7b1a777
3 changed files with 99 additions and 17 deletions

View File

@@ -36,6 +36,11 @@ ansible-playbook 'gitlab.yml' \
ansible-playbook 'prometheus.yml' \
-i 'aws_ec2.yml' -e 'ansible_aws_ssm_plugin=/usr/local/sessionmanagerplugin/bin/session-manager-plugin' \
-D -t 'cron' -l 'i-0123456789abcdef0' -C
ansible-playbook 'playbook.yaml' \
-e 'ansible_aws_ssm_plugin=/usr/local/sessionmanagerplugin/bin/session-manager-plugin' \
-e 'ansible_connection=aws_ssm' -e 'ansible_aws_ssm_bucket_name=ssm-bucket' -e 'ansible_aws_ssm_region=eu-west-1' \
-e 'ansible_remote_tmp=/tmp/.ansible-\${USER}/tmp' \
-i 'i-0123456789abcdef0,' -D
ANSIBLE_ENABLE_TASK_DEBUGGER=True ansible-playbook …
ANSIBLE_CALLBACKS_ENABLED='profile_tasks' ansible-playbook …

View File

@@ -12,6 +12,13 @@
path: /tmp/path/to/final/dir
state: directory
- name: Write files from tasks
ansible.builtin.copy:
dest: "{{ ansible_user_dir }}/.tmux.conf"
mode: u=rw,go=r
content: |
- name: Import tasks
block:
- name: By using absolute paths and special variables (preferred)
@@ -64,24 +71,53 @@
ansible.builtin.debug:
msg: "{{ lookup('ansible.builtin.password', '/dev/null', seed=inventory_hostname) }}"
- name: Add repositories
block:
- name: DNF/YUM
ansible.builtin.yum_repository:
name: epel
description: EPEL YUM repo
baseurl: https://download.fedoraproject.org/pub/epel/$releasever/$basearch/
- name: Install packages
block:
- name: Generic module
ansible.builtin.package:
name:
- tmux
- screen
- name: Via PIP
ansible.builtin.pip:
name:
- bottle
- django>1.11.0,<1.12.0
- svn+http://myrepo/svn/MyApp#egg=MyApp
- git+http://myrepo/app/MyApp
- file:///path/to/MyApp.tar.gz
- name: Run containers
community.docker.docker_container:
name: gitlab
image: gitlab/gitlab-ce:16.11.2-ce.0
hostname: gitlab.lan
published_ports:
- "8022:22"
- "8080:80"
- "8443:443"
env:
GITLAB_OMNIBUS_CONFIG: >-
external_url 'http://gitlab.lan';
shm_size: 256m
volumes:
- ./config:/etc/gitlab:Z
- ./logs:/var/log/gitlab:Z
- ./data:/var/opt/gitlab:Z
auto_remove: true
block:
- name: Directly
community.docker.docker_container:
name: gitlab
image: gitlab/gitlab-ce:16.11.2-ce.0
hostname: gitlab.lan
published_ports:
- "8022:22"
- "8080:80"
- "8443:443"
env:
GITLAB_OMNIBUS_CONFIG: >-
external_url 'http://gitlab.lan';
shm_size: 256m
volumes:
- ./config:/etc/gitlab:Z
- ./logs:/var/log/gitlab:Z
- ./data:/var/opt/gitlab:Z
auto_remove: true
- name: With Compose
community.docker.docker_compose_v2:
project_src: /home/user/flask
- name: Manipulate strings
ansible.builtin.set_fact:

View File

@@ -0,0 +1,41 @@
/**
* Run commands after creation
* -----------------------------------------------------------------------------
*
* Replace the 'command.local.Command' resource to run it again:
* `pulumi up --replace "urn:pulumi:any::stackName::command:local:Command::ansiblePlaybook-ssh"`
**/
import * as aws from "@pulumi/aws";
import * as command from "@pulumi/command";
const instance = new aws.ec2.Instance(
"instance",
{ }
);
command.local.Command(
"notify",
{ create: "say 'instance created'" }
);
instance.privateDns.apply(host => new command.local.Command(
"ansiblePlaybook-ssh",
{ create: `ansible-playbook -i '${host},' -D 'playbook.yaml'` },
));
instance.id.apply(id => new command.local.Command(
"ansiblePlaybook-awsSsm",
{
create: `
ansible-playbook
-e 'ansible_aws_ssm_plugin=/usr/local/sessionmanagerplugin/bin/session-manager-plugin'
-e 'ansible_connection=aws_ssm'
-e 'ansible_aws_ssm_bucket_name=ssm-bucket'
-e 'ansible_aws_ssm_region=eu-west-1'
-e 'ansible_remote_tmp=/tmp/.ansible-\${USER}/tmp'
-i '${id},'
-D 'playbook.yaml'
`,
},
));