コンテンツへスキップ

ファイル

root@localhost myProject]# tree
.
|-- ansible.cfg
|-- group_vars
|   `-- db.yml
|-- hosts
|-- roles
|   |-- postgresql
|   |   |-- defaults
|   |   |   `-- main.yml
|   |   |-- handlers
|   |   |   `-- main.yml
|   |   |-- tasks
|   |   |   |-- configurations.yml
|   |   |   |-- createDbCluster.yml
|   |   |   |-- main.yml
|   |   |   |-- packages.yml
|   |   |   `-- services.yml
|   |   `-- templates
|   |       `-- postgresql.conf.j2
|   `-- test1
|       `-- tasks
|           |-- hashTest.yml
|           `-- main.yml
`-- site.yml

9 directories, 14 files

db.yml

[root@localhost myProject]# more group_vars/db.yml
---
postgresql_version: "12"

dbs:
  db1:
    dataDirectory: /var/lib/pgsql/data1
    port: 5432
  db2:
    dataDirectory: /var/lib/pgsql/data2
    port: 5433

task

[root@localhost myProject]# more roles/test1/tasks/main.yml
- name: "hash test"
  import_tasks: hashTest.yml
[root@localhost myProject]# more roles/test1/tasks/hashTest.yml
---
- name: "print dict"
  #debug:
  #  var: item
  file: path={{ item.value.dataDirectory }} state=directory owner=root group=root mode=0755
  with_dict: "{{ dbs }}"

実行結果

[root@localhost myProject]# ansible-playbook -i ./hosts site.yml
/usr/lib/python2.7/site-packages/ansible/parsing/vault/__init__.py:44: CryptographyDeprecationWarning: Python 2 is no longer supported by the Python core team. Support for it is now deprecated in cryptography, and will be removed in the next release.
  from cryptography.exceptions import InvalidSignature

PLAY [db] *********************************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************
ok: [localhost]

TASK [test1 : print dict] *****************************************************************************************************************************************************
changed: [localhost] => (item={u'key': u'db1', u'value': {u'dataDirectory': u'/var/lib/pgsql/data1', u'port': 5432}})
changed: [localhost] => (item={u'key': u'db2', u'value': {u'dataDirectory': u'/var/lib/pgsql/data2', u'port': 5433}})

PLAY RECAP ********************************************************************************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

 

$e = New-Object -ComObject Excel.Application
$e.Visible = $true
$book  = $e.Workbooks.Add()
$sheet = $book.Worksheets.Item(1)
$sheet.Cells.Item(7,3) = "実線"

# ------< 実線 >----------
$sheet.cells.item(7.3).borders.LineStyle = 1 #実線
#$sheet.cells.item(7,3).borders.Weight = 2    # 線の太さ

# 列幅を自動調整する
$range = $sheet.usedRange
$range.EntireColumn.AutoFit() | out-null

# セルの結合
$c1 = $sheet.Cells(2,3)
$c2 = $sheet.Cells(2,4)
$sheet.range($c1,$c2).mergeCells = 1
$sheet.cells.item(2,3).borders.Weight = 2    # 線の太さ
$sheet.cells.item(2,4).borders.Weight = 2    # 線の太さ

# Excelを閉じる
$e.Quit()
# プロセスを解放する
$e = $null
[GC]::Collect()

 

他のブックのシートをコピーする。

$file1 = 'E:\my-document\エクセル\template.xlsx' # source's fullpath
$file2 = 'E:\my-document\エクセル\Test05.xlsx' # destination's fullpath
$xl = new-object -c excel.application
$xl.displayAlerts = $false # don't prompt the user
$xl.visible = $true
$workBook1 = $xl.workbooks.open($file1, $null, $true) # open source, readonly
#$workBook2 = $xl.workbooks.open($file2) # open target

# 新しいbookを作成
$workBook2 = $xl.Workbooks.Add() # index1に追加される

# コピーするシートをセット
$sheetToCopy = $workBook1.sheets.item('テンプレートシート') # source sheet to copy

#シート名アレイ
$sheetLists = ("サーバ1","サーバ2","サーバ3")

$i = 1
foreach($sheetName in $sheetLists) {
    $sh1_wb2 = $workBook2.sheets.item($i)
    $sheetToCopy.copy($sh1_wb2)
    $workBook2.WorkSheets.item("テンプレートシート").name = [string]$sheetName
    $i++
}

# ブック作成時にデフォルトで作成されるシートを削除
$workBook2.WorkSheets.item("Sheet1").delete()
$workBook2.WorkSheets.item("Sheet2").delete()
$workBook2.WorkSheets.item("Sheet3").delete()

$workBook1.close($false) # 保存なし
$workBook2.SaveAs($file2)
#$workBook2.close($true) # 保存あり
$xl.quit()
$xl = $null
[gc]::Collect()